Nick LaMarca
Nick LaMarca

Reputation: 8188

Page Breaks In Excel VB.Net

I'm working with the Office Interop and having trouble inserting page breaks in Excel. My code is working fine with the horizontal page break but I also need to set the vertical pagebreak. Can somone modify my code below, to make a vertical page break on column I?

This code is making the correct horizontal pagebreaks but is still 150 pages long because the vertical pagebreak is not set correctly.

Dim r As Excel.Range = CType(xlWorkSheet.Cells(27, 1), Excel.Range)

r.PageBreak = 1

Upvotes: 4

Views: 6772

Answers (3)

James Toomey
James Toomey

Reputation: 6082

This

sheet.VPageBreaks.Add(sheet.Range["J1"]); 

worked for me to set a vertical page break. As shown in the picture, it seems to put the page break before the specified column: enter image description here

Upvotes: 4

Dhaval
Dhaval

Reputation: 1

If you want page like A1:D15
for that

excelWorksheet.Range(E16).PageBreak = 1 

It will create both vertical and horizontal page break.

This is just example. Code accordingly.

Upvotes: 0

M.A. Hanin
M.A. Hanin

Reputation: 8074

Try setting the vertical pagebreak for the right Column object itself, rather than the cells range.

Upvotes: 0

Related Questions