VBA Dumb Problem of the Day
Sure, many of us loathe VBA, but we still have to support it. I was trying to update an Excel macro that configured a print layout and suddenly I was unable to insert page breaks. “It was working a second ago”.
Run-time error ‘1004’: unable to set the PageBreak property of the Range class
Turns out that when applied to my test data the PrintArea of the print layout was set so that the first row I was trying to add a page break to was also the first row of the PrintArea. I guess it makes sense but that isn’t documented anywhere.
So if you’ve been trying a dozen different ways of adding a page break, do yourself a favour and double check the area selected for printing. If you’re trying to add a page break on the border of your selection it’ll fail.