为什么说“自动化错误”
代码如下:
Private Sub Command1_Click()
Dim myDoc, WordApp As Object
Set WordApp = CreateObject("Word.Application")
Set myDoc = WordApp.Documents.Add()
WordApp.Visible = False
With WordApp.ActiveDocument.PageSetup
.TopMargin = WordApp.CentimetersToPoints(2.54) '上边距,厘米
.BottomMargin = WordApp.CentimetersToPoints(2.54) '下边距
.LeftMargin = WordApp.CentimetersToPoints(3.17) '左边距
.RightMargin = WordApp.CentimetersToPoints(3.17) '右边距
.PageWidth = WordApp.CentimetersToPoints(29.7) '纸宽
.PageHeight = WordApp.CentimetersToPoints(42) '纸高
End With
WordApp.ActiveDocument.SaveAs App.Path & "\aaa.doc"
WordApp.Quit
Set WordApp = Nothing
myDoc.Quit‘自动化错误
Set myDoc = Nothing
End Sub
[解决办法]
按你的代码myDoc是一个document对象,没有quit方法
改为:
WordApp.quit