fixing page break in my macro

spacecaptainsuperguy

Board Regular
Joined
Dec 30, 2004
Messages
202
Office Version
  1. 365
Platform
  1. Windows
I have a macro that when I recorded it, I used the page break preview to make sure that the document would only be one page width wide. I used the page break mode to drag the page break out to the edge of the document. All has worked fine (for years now) until I ran into a document that was only one page wide already. Here is the chunk of code that I'm having the issue with and it's the 2nd line that is creating the error.

ActiveWindow.View = xlPageBreakPreview
ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
ActiveWindow.View = xlNormalView

I know there must be a way to tell the macro to only do this if the document is larger than one page wide but I haven't been able to figure out how to do that.

Any thoughts?
thanks in advance.
SpaceCaptainSuperGuy
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try using
Code:
ActiveSheet.PageSetup.FitToPagesWide = 1
instead of the vpagebreaks() line.

this is the (edited) code from using the page setup dialog.
 
Upvote 0
Awesome. I'll give that a try................worked perfectly.
Thanks so much.
I'm always amazed at how simple the fix is if you know how to fix it and how difficult it is when you're clueless.
Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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