CodeItBetter Programming Another VB Programming Blog

How to use Microsoft Word to print output from VB

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'MS Office - How to use Microsoft Word to print output from VB
'This code uses Microsoft Word to print output from VB.
'First, you need to set a reference to the Word 8.0/9.0/10.0/11.0 Object Model.
'Place the following code in a click event.

Private Sub cmdPrint_Click()
    Dim WordApp As Word.Application
    Dim WordDoc As Word.Document
    Dim WordSel As Word.Selection
 
    Set WordApp = New Word.Application
    Set WordDoc = Word.Documents.Add
    Set WordSel = Word.Selection
 
    WordSel.TypeText = "Enter text to print here."
    WordSel.Font.Name = "verdana"
    WordSel.FontSize = 10
 
    'Print Document
    WordDoc.PrintOut
 
    Set WordApp = Nothing
    Set WordDoc = Nothing
    Set WordSel = Nothing
End Sub
Filed under: MS Office Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.