如何用VB新建一个空白word文档并打开?

2024-12-29 15:44:15
推荐回答(3个)
回答1:

Private Sub Command1_Click()
Dim myDoc, WordApp As Object
Set WordApp = CreateObject("Word.Application")
Set myDoc = WordApp.Documents.Add()
myDoc.SaveAs "c:\新建 Microsoft Word 文档.doc"
End Sub

回答2:

Private Sub Form_Load()
Dim myDoc, WordApp As Object
Dim filename As String
Set WordApp = CreateObject("Word.Application")
Set myDoc = WordApp.Documents.Add()
filename = App.Path & "\新建 Microsoft Word 文档.doc"
myDoc.SaveAs filename
End Sub

回答3:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
Open "c:\新建文档.doc" For Output As #1
Print #1, "这是用VB新建的文档"
Close
ShellExecute Me.hwnd, "open", "c:\新建文档.doc", vbNullString, vbNullString, 5
End
End Sub