troubleshooting Question

Excel pagebreak from VB code

Avatar of Norma Posy
Norma PosyFlag for United States of America asked on
Visual Basic Classic
4 Comments1 Solution353 ViewsLast Modified:
My app creates an Excel spreadsheet.
There are places where a page break is needed.
Code snippet:

Dim oXLApp As Object
Dim oXLBook As Object
Dim oXLSheet As Object

Set oXLApp = CreateObject("Excel.Application")
Set oXLBook = oXLApp.Workbooks.Add
Set oXLSheet = oXLBook.Worksheets(1)

If [condition is met] Then
   sRange = "A" & Trim(CStr(iRow))
   oXLSheet.HPagebreaks.Add Before:=oXLSheet.Range(sRange)
End If

I've stepped through the code, and [condition is met] is detected, and the if-then is executed. But nothing happens. No page break occurs.

Please help.
ASKER CERTIFIED SOLUTION
Éric Moreau
Senior .Net Consultant
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros