Link to home
Start Free TrialLog in
Avatar of Norma Posy
Norma PosyFlag for United States of America

asked on

Excel "page break"

My application generates a number of Excel spreadsheets.

What is the syntax for creating a page break at a specified row number?
Avatar of Brook Braswell
Brook Braswell
Flag of United States of America image

   ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
    ActiveWindow.SelectedSheets.VPageBreaks.Add Before:=ActiveCell
Avatar of Norma Posy

ASKER

Like this?

Dim oXL As Object
Set oXL = CreateObject("Excel.Application")
With oXL
	.Visible = True
	sCurrentName = .Workbooks.Add.Name
'
' build spreadsheet
'
        .Range("A:50").Value = strSeeding(iIndex)
	.Row = 51
	.SelectedSheets.VPageBreaks.Add Before:=ActiveCell	
End With

Open in new window

sRow = Trim(CStr(iRow))
sCellNumber = sRow & ":" & sRow
.Rows(sCellNumber).Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=sCellNumber ' ActiveCell

Open in new window


Error: "Variable not defined"
 ActiveWondow is highlighted
Dim oXLBook As Object
Dim oXLSheet As Object
Dim oXLReport As Object
'
Set oXLReport = CreateObject("Excel.Application")
Set oXLBook = oXLReport.Workbooks.Open
Set oXLSheet = oXLBook.Worksheets(1)
With oXLReport
   .Visible = True
   .Workbooks.Add
'
' build spreadsheet
'
' ===== insert page break
   oXLSheet.HPagebreaks.Add Before:=oXLSheet.Range("A5")
End With

Open in new window


Line 6: Error: "Argument not optional"

Please help
ASKER CERTIFIED SOLUTION
Avatar of Brook Braswell
Brook Braswell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The variable Not Defined could be your sCellNumber was not identified
Looks like you are on the right track to me.
taking yours above after modifying line 6 creates a blank WB with a page break at A5
Thank You!