October 1998
Intermediate to advanced
656 pages
16h 10m
English
So let's bring together all you've seen in this chapter with a few sample implementations of OLE automation servers.
This first application demonstrates how you can seamlessly use Microsoft Word to print output from your VB program without the user knowing that you have actually used Microsoft Word:
Private Sub cmdWordDoc_Click()
'create an error handler
On Error GoTo cmdWordDoc_Err
'create the local Early Bound object variables
Dim oWord As Word.Application
Dim oWordActiveDoc As Word.Document
Dim oWordSel As Word.Selection
'Create a new instance of Word
Set oWord = New Word.Application
'Create a new document object
Set oWordActiveDoc = oWord.Documents.Add
Set oWordSel = oWord.Selection
'Do some work with the Selection object
oWordSel.TypeText "This is some text from the VB app."
oWordSel.WholeStory
oWordSel.Font.Name = "Arial"
oWordSel.Font.Size = 12
oWordSel.Font.Bold = wdToggle
'Now print out the doc
oWordActiveDoc.PrintOut
'always tidy up before you leave
Set oWordSel = Nothing
Set oWordActiveDoc = Nothing
Set oWord = Nothing
Exit Sub
cmdWordDoc_Err:
MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf _
& Err.Source
End Sub
Because this example uses early binding, you'll have to use the References dialog to add a project reference to the Word 8 Object Model.
|
Read now
Unlock full access