| Add a
reference to the Word object library
. Project / References . Then scroll
down and place a tick beside the Microsoft
Word object library.
Place a command button on a form.
Private Sub Command1_Click()
Dim objWord As Word.Document
Dim result As Integer
Set objWord = New Word.Document
With objWord.ActiveWindow.Selection
'text in document
.TypeText "This is some sample
text"
'new paragraph
.TypeParagraph
.TypeText "This is some more
text"
.TypeParagraph
result = MsgBox("Word Document
Created Successfully", vbInformation,
"WD Created")
End With
With objWord
'save document location
.SaveAs "h:\mysampledoc.doc"
.Close
End With
'destroy word object
Set objWord = Nothing
End Sub
|