PageSetup.PrintArea - Automation Error

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
Office Version
  1. 365
Platform
  1. Windows
I have been using the following code to set up a print range
VBA Code:
strPrintRange = Range("Dashboard_OutputAll").Address
            
ActiveSheet.PageSetup.PrintArea = strPrintRange
All worked as required until it didn't for no reason.

strPrintRange is a string variable of "$B$2:$Z$1088"

I am now getting the following error
Run-time error '-2147319767 (80028029)':

automation error
Invalid forward reference, or reference to uncompiled type


I have been tweaking code in the procedure to sort out page breaks, etc but other than this, no major difference between when it did work an when it stopped working.


TIA
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
UPDATE

Strangely, when I activate another workbook that is open and allow the code to execute, it executes and sets up the defined range in the active workbook.

If I then activate the correct workbook and re-run that line of code, I get the error again.

Assuming it's something tot do with the file but I've never seen this kind of issue before.
 
Upvote 0
FURTHER UPDATE

With the Activesheet, I set this up as a Worksheet variable and changed the code to
VBA Code:
wsCRMDb.PageSetup.PrintArea = strPrintRange
Which worked......

No idea why the Activesheet stopped working but I suppose I have a fix!
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,197
Latest member
k_bs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top