Why go I get error 1004 when calling a macro from Word doc, but not from 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.
Try using a comma delimited list instead of semicolon
.PrintArea = "$A$1:$O$49,$Q$1:$AE$49,$Q$50:$AE$97,$AG$50:$AU$97"
精彩评论