Avatar of AVSteve
AVSteve
 asked on

ActiveSheet.PageSetup.PrintArea

I'm running office 2010 and recently added visual studio pro 2008 (requried by a project I am starting).  I've also kept up with Microsoft updates so I've made some of those too.  How my excel VBA macros don't work.  A snippet of code which stops with "application defined or object-defined error on the last line.

Application.Calculate
Range("end_end").value = activerows + 5
ActiveWorkbook.Names("Master").RefersTo = "=pricing!$f$6:$bn$" & LTrim(Str(activerows + 5))
ActiveWorkbook.Names("Dealers").RefersTo = "personal.xls!dealers"
noter = 0

pr = "$a$1:$bn$" & LTrim(Str(activerows + nr + 6))
ActiveSheet.PageSetup.PrintArea = pr


Code worked before but not now
Microsoft ExcelVB ScriptMicrosoft ApplicationsVBA

Avatar of undefined
Last Comment
AVSteve

8/22/2022 - Mon
Saqib Husain

What is the value of pr at this stage?
dsacker

You may need to post your xlsx files (or an excerpt representation of them). Trying to reproduce your code is not possible, considering it is guesswork to set up the Master, Dealers, Pricing and Personal.xls references.

Other than that, I got no error on the line: ActiveSheet.PageSetup.PrintArea = pr
However, I fudged the value in "pr".
Norie

Where does the error occur?

Have you stepped through the code to check the values of the variables?

By the way, why are you using LTrim and Str?

You shouldn't need thten when concatenating.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
AVSteve

ASKER
ok, I've learned some more.  My macros come (for the most part) from a personal.xls which is xlstart so it always there.  the file is hidden so it doesn't confuse a user,  All used to work.  Now with the updates it doesn't work --- sortof.

If I open the macro file itself and run the macro (no hidden macro file), it works.  if I remove the hidden macro file, start a new program copy the macro in -- it works.

The problem is that the macro comes from what I would call a macro library and when running is confused about what an "actitivesheet" is.   Is there a different way to do a macro library?  A way to ensure the right context?  A way to say activesheet (and similar) without saying it?
AVSteve

ASKER
Apparently the righter-way for a macro library is an add-in.  I tried that.  Still no joy.  And the problem also effects the selection object as well as the active sheet one.
Wayne Taylor (webtubbs)

ActiveSheet used in the Personal.xlsx file will work fine. I suspect the error lies elsewhere. Please try what Norie stated and step through the macro and check the values of "activerows" and "nr" (hover over them to view their values)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
AVSteve

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
AVSteve

ASKER
The other answers might have led to this resolution but they never followed up their initial posts.