run time error deleting vpagebreak

berlinhammer

Board Regular
Joined
Jan 30, 2009
Messages
187
Hello

I am having a very irritating runtime error that I can't understand the cause of. I'm trying to macro a dynamic print area and in the process delete a vertical pagebreak I don't want, the code keeps tripping on an error 1004 application defined/object defined and I can't understand why. Does anyone have any ideas based on the codes below? I've tried all three and none seem to work.

Many thanks

Jon


Code:
Sub PrintEntity()
Dim output As Range
Dim sh As Worksheet
Dim vpbL As VPageBreak

Set sh = ThisWorkbook.Sheets("P&L Summary")
Set output = sh.Range("rngOutput").CurrentRegion
Set vpbL = sh.VPageBreaks(1)

sh.Range("rngFilter").AutoFilter Field:=1, Criteria1:="TRUE"
sh.ResetAllPageBreaks
sh.PageSetup.PrintArea = output.Address

vpbL.Delete
End Sub

Code:
Sub x()
With ActiveSheet
   If .VPageBreaks.Count > 0 Then
      .VPageBreaks(1).Delete
   End If
End With
End Sub

Code:
Sub y()
ActiveSheet.VPageBreaks(1).Delete
End Sub
 
Last edited:

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

berlinhammer

Board Regular
Joined
Jan 30, 2009
Messages
187
Hi Mohammad,

Thanks for your reply.

Nope not me, when I reset the page breaks (as in the VBA) Excel seems to create it automatically, very annoying! Any ideas?

Jon
 

Mohammad Basem

Well-known Member
Joined
Dec 24, 2011
Messages
1,218
Excel cannot delete automatic page breaks.

However, if you don't want to show page breaks on the sheet use ActiveSheet.DisplayPageBreaks = False
 

berlinhammer

Board Regular
Joined
Jan 30, 2009
Messages
187
Hi Mohammad,

Thanks for replying. That surprises me, but I managed to get something working using PrintCommunication. The ActiveSheet.DisplayPageBreaks = False didn't work for my purposes unfortunately.

Cheers

Jon

Code:
 Sub PrintEntity()
Dim output As Range
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("P&L Summary")
sh.Range("rngFilter").AutoFilter Field:=1, Criteria1:="TRUE"
Set output = sh.Range("rngOutput").CurrentRegion
sh.PageSetup.PrintArea = output.Address
sh.ResetAllPageBreaks
Application.PrintCommunication = False
sh.PageSetup.FitToPagesWide = 1
sh.PageSetup.FitToPagesTall = 0
Application.PrintCommunication = True
End Sub
 

Mohammad Basem

Well-known Member
Joined
Dec 24, 2011
Messages
1,218
ActiveSheet.DisplayPageBreaks = False hides the page breaks in the normal view. It is not permanent though.
It has no effect in the page break view. Also, sometimes the page breaks reappear after modifying the page setup.

Application.PrintCommunication enables/disables communication with the printer. If False, it speeds up execution of the code that sets page setup properties.

In your code, you have scaled down the printout to fit on one page and that’s why the page breaks disappeared.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,483
Messages
5,596,405
Members
414,064
Latest member
Duncthegreat

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
Top