Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2013 - Page setup wrong. 1

Status
Not open for further replies.

sduraiappan

Programmer
Sep 17, 2002
14
CN
I am using this code in my Vb.Net application to add some empty rows in a worksheet:

Dim TPAGECOUNT = WKSHEET.PageSetup.Pages.Count
Do While TPAGECOUNT = WKSHEET.PageSetup.Pages.Count
WKSHEET.Range("A" & TROW & ":R" & TROW).Rows.Insert(Shift:=EXCEL.XlInsertShiftDirection.xlShiftDown)
TROW = TROW + 1
WKSHEET.PageSetup.PrintArea = "A1:" & TCOL & TROW + 10
Loop

This code works fine in system having Excel 2007 and the entire content is fit to one page.

If I run the same application in a system having Excel 2013, I find one extra row and hence the page count is increased by 1.

I could not locate the issue.

Can anyone please help me.

Regards,

S.Duraiappan.
 
You first check pages number and next add row, the loop stops when there is already one page more than initially. Depending on rows height (equal or some are higher) either test with bigger print area area (WKSHEET.PageSetup.PrintArea = "A1:" & TCOL & TROW + 11) and decrease it, or delete one added row, any of this after quitting the loop.

combo
 
Thanks for the idea.

I delete one row after the loop.

Works fine.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top