Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error 1004
I have a sub on a worksheet calculate area and the sub has these 4 lines:
Sheets("Results").Select Set Rng = Range("nonvalidreport") ActiveSheet.PageSetup.PrintArea = Rng.Address ActiveWindow.SelectedSheets.PrintPreview The sub is not on this sheet. But I get an error 1004 on line 2. If I run these 4 lines in a module it works, but I can't figure out how to call a sub in a module from the area where I am. HELP! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error 1004
Try
Set Rng = Sheets("Results").Range("nonvalidreport") "Mike H." wrote in message ... I have a sub on a worksheet calculate area and the sub has these 4 lines: Sheets("Results").Select Set Rng = Range("nonvalidreport") ActiveSheet.PageSetup.PrintArea = Rng.Address ActiveWindow.SelectedSheets.PrintPreview The sub is not on this sheet. But I get an error 1004 on line 2. If I run these 4 lines in a module it works, but I can't figure out how to call a sub in a module from the area where I am. HELP! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error 1004
If you're code is in a worksheet module, then those unqualified ranges will
refer to the worksheet that owns the code. And that worksheet may not have a range named "nonvalidreport". I'd use this: with worksheets("Results") '.select 'not necessary to select set rng = .range("nonvalidreport") .pagesetup.printarea = rng.address .printout preview:=true end with or this: worksheets("results").range("nonvalidreport").prin tout preview:=true If I didn't really want to change the .pagesetup.printarea, then the one-liner would be easier to understand (for me). Mike H. wrote: I have a sub on a worksheet calculate area and the sub has these 4 lines: Sheets("Results").Select Set Rng = Range("nonvalidreport") ActiveSheet.PageSetup.PrintArea = Rng.Address ActiveWindow.SelectedSheets.PrintPreview The sub is not on this sheet. But I get an error 1004 on line 2. If I run these 4 lines in a module it works, but I can't figure out how to call a sub in a module from the area where I am. HELP! -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
run time error 1004 general odbc error excel 2003 vba | Excel Programming | |||
runtime error '1004' application or object defined error. Please help | Excel Programming | |||
Error 1004, Application-definded or object-defined error | Excel Programming | |||
run-time error '1004': Application-defined or object-deifined error | Excel Programming | |||
Excel 2003 Macro Error - Runtime error 1004 | Excel Discussion (Misc queries) |