Problem when setting Zoom to False

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
275
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2011
Platform
  1. Windows
  2. MacOS
I have a sub that prepares a sheet to be printed. Several sheets share this sub, as they all need to have the same Print Area, etc. This sub gets called each time one of the sheets needs to be printed. I've run across a problem that only happens when I'm stepping through my code.

Here's the chunk of code in question.

Code:
PrintAreaRange = "C4:" & LastColumnLetter & "213"

With ThisWorkbook.Sheets(SheetName).PageSetup

    .PrintArea = Range(PrintAreaRange).Address
    .Orientation = xlLandscape
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = False
    .PrintTitleRows = "$4:$9"

End With

If I run the code normally, it works fine. However, if I'm stepping through the code, after the .Zoom = False line, I get the following message on Excel:

The number must be between 10 and 400. Try again by entering a number in this range.

(I believe I found this code on this forum somewhere a few months back and adjusted it to fit my needs. So I'm not 100% sure if the line with the .Zoom = False is necessary, but I assume it is since it was in the code example I found here.)

I don't understand why this code works fine when it's run normally, but gives this message when I'm stepping through it. Any ideas?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I don't know the cause and I cannot reproduce the error but just as a test, what happens if you add this extra line?
Rich (BB code):
.Zoom = 100
.Zoom = False
I think that you do need that .Zoom = False line though

BTW, you could simplify your printarea line. Currently you are taking a range address, referring to that range and then getting the address of that range. That just brings you back to where you started. :)
Rich (BB code):
<del>.PrintArea = Range(PrintAreaRange).Address</del>
.PrintArea = PrintAreaRange
 
Upvote 0
I added that line you suggested. When stepping through the code, that line didn't cause any problems. However, when I got to the next line (.Zoom = False), I received the same error as before. Since it works fine when running the code normally, I'll leave it in there, but seems odd that it gives that error message when stepping through.
 
Upvote 0

Forum statistics

Threads
1,215,463
Messages
6,124,963
Members
449,200
Latest member
indiansth

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