说明(2017.3.20):
1. Dim As声明变量类型,Set赋值/初始化
2. With使后面的省略对象,直接点就行,后面要End With
3. Application.StatusBar = "正在创建word",这个会在Excel左下角出现提示
4. .ActiveDocument.SaveAs2(),里面第一个参数是文件名,需要加地址,不然不行
5. 最后记得加Quit,wordApp要清零(释放对象实例,收回该对象占用的内存),Application.StatusBar要false(将状态栏上的信息恢复为默认的“就绪”)
Public Sub dianbo() Dim wordApp As Word.Application
Application.StatusBar = "正在创建。。。"
Set wordApp = New Word.Application With wordApp
.Visible = True
Application.StatusBar = "正在创建word"
.Documents.Add
.ActiveDocument.Paragraphs().Range.InsertBefore ("邀请函")
Application.StatusBar = "正在保存"
.ActiveDocument.SaveAs2 ("D:\工作\脚本下载\vba练习\test.docx")
Application.StatusBar = "正在退出"
.Quit
End With
Set wordApp = Nothing
Application.StatusBar = False
End Sub