#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
run time error 1004 general odbc error excel 2003 vba Mentos Excel Programming 5 January 24th 11 02:56 PM
runtime error '1004' application or object defined error. Please help deej Excel Programming 0 August 1st 07 09:26 AM
Error 1004, Application-definded or object-defined error Mirco Wilhelm[_2_] Excel Programming 9 January 7th 06 04:56 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


All times are GMT +1. The time now is 09:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"