为什么从 Word 文档调用宏时出现错误 1004,而不是从 Excel 调用宏?
在 Word 文件中,我有一个宏,可以打开 Excel 文件并调用该文件中的宏。 (我使用的是 VBA。)这是来自 Word 的简单代码:
Set oExcelApp = CreateObject("Excel.Application")
Set oWorkbook = oExcelApp.workbooks.Open("C:\Documents and Settings\Eddy\Mina dokument\Insajt\Arbeten\Prido\Affärssystem\www\modules\mod_order\eco.xls")
oExcelApp.Visible = True
oExcelApp.Run "'ECO.xls'!Ritning"
Excel 文件打开并运行宏,但随后我收到错误提示(翻译自瑞典语。):
运行时错误 '1004 ' 无法为类、PageSetup 输入 PrintArea 属性
如果我选择调试模式,这一行会突出显示:
.PrintArea = "$A$1:$O$49;$Q$1:$AE$49;$Q$50:$AE$97;$AG$50:$AU$97"
整个代码段是这样的:
If Sheets("Beräkningar").Cells(6, 2) = "4V" Then
With Sheets("Ritn").PageSetup
.PrintArea = "$A$1:$O$49;$Q$1:$AE$49;$Q$50:$AE$97;$AG$50:$AU$97"
.Zoom = 85
End With
Sheets("Ritn").PrintOut
End If
现在到了真正奇怪的事情。如果我中止对 Excel 文件中宏的调用并仅手动调用相同的宏,它就会像魅力一样工作。同样,如果我手动打开 Excel 文件并启动宏,则一切正常。
In a Word file, I have a macro that opens an Excel file and calls for a macro in that file. (I'm using VBA.) This is the simple code from Word:
Set oExcelApp = CreateObject("Excel.Application")
Set oWorkbook = oExcelApp.workbooks.Open("C:\Documents and Settings\Eddy\Mina dokument\Insajt\Arbeten\Prido\Affärssystem\www\modules\mod_order\eco.xls")
oExcelApp.Visible = True
oExcelApp.Run "'ECO.xls'!Ritning"
The Excel file opens and the macro runs, but then I get an error prompt (translated from Swedish.):
Run-time error '1004 '
PrintArea property can not be entered for the class, PageSetup
If I choose Debug mode, this line is highlighted:
.PrintArea = "$A$1:$O$49;$Q$1:$AE$49;$Q$50:$AE$97;$AG$50:$AU$97"
The whole section of code is this:
If Sheets("Beräkningar").Cells(6, 2) = "4V" Then
With Sheets("Ritn").PageSetup
.PrintArea = "$A$1:$O$49;$Q$1:$AE$49;$Q$50:$AE$97;$AG$50:$AU$97"
.Zoom = 85
End With
Sheets("Ritn").PrintOut
End If
Now to the really strange thing. If I abort the call for the macro in the Excel file and just manually call the same macro, it works like a charm. Same if I manually open the Excel file and start the macro, then everything works fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用逗号分隔列表而不是分号
Try using a comma delimited list instead of semicolon