工程必须引用 Word 类库 ' Declare the variable. Dim objWD As Word.Application Dim strTemp As String, i As Long For i = 0 To List1.ListCount strTemp = strTemp & List1.List(i) & vbNewLine Next i ' Set the variable (runs new instance of Word.) Set objWD = CreateObject("Word.Application") ' Add a new document. objWD.Documents.Add ' Add some text. objWD.Selection.TypeText strTemp ' Save the document. objWD.ActiveDocument.SaveAs filename:="mydoc.doc" ' Quit Word. objWD.Quit ' Clear the variable from memory. Set objWD = Nothing
Dim objWD As Word.Application
Dim strTemp As String, i As Long For i = 0 To List1.ListCount
strTemp = strTemp & List1.List(i) & vbNewLine
Next i ' Set the variable (runs new instance of Word.)
Set objWD = CreateObject("Word.Application")
' Add a new document.
objWD.Documents.Add
' Add some text.
objWD.Selection.TypeText strTemp
' Save the document.
objWD.ActiveDocument.SaveAs filename:="mydoc.doc"
' Quit Word.
objWD.Quit
' Clear the variable from memory.
Set objWD = Nothing