OK this is not a question, just a discovery.
I am doing some reporting in Excel programatically. In the main loop, I was adding a page break where it was supposed to go like:
VB Code:
mwksTemp.HPageBreaks.Add rngReport.Range(strRange)
This was making my code run increadibly slow, approx. 100 times slower if not worse.
Instead, I saved the placement of the pagebreak in a collection like:
VB Code:
colPageBreaks.Add strRange
and, after the looping was all finished, I add the page breaks like:
VB Code:
For each varPageBreak in colPageBreaks mwksTemp.HPageBreaks.Add rngReport.Range(varPageBreak) Next
The lesson is only to never place pagebreaks inside of a looping algorithm because of the insane time growth problem.


Reply With Quote