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
ASKER
Private Sub TestPageBreak_Click()
Dim iI As Integer
Dim sCellNumber As String
Dim oXLApp As Object
Dim oXLBook As Object
Dim oXLSheet As Object
Dim sWorkbookName As String
Dim sCurrentName As String
'
Set oXLApp = CreateObject("Excel.Application")
Set oXLBook = oXLApp.Workbooks.Add
Set oXLSheet = oXLBook.Worksheets(1)
sWorkbookName = "Testing.xls"
'
With oXLApp
.Visible = True
sCurrentName = .Workbooks.Add.Name
With .Range("A1:F300")
.Font.Name = "Courier New"
.Font.Size = 10
End With
.Range("A1:A200").ColumnWidth = 5
.Columns("A:A").Select
.Selection.HorizontalAlignment = xlCenter
'
' Insert Cell Data
For iI = 1 To 6
sCellNumber = "A" & CStr(Trim(iI))
.Range(sCellNumber).Value = iI
Next iI
' Page Break
' (alternate try:)
' oXLSheet.HPagebreaks.Add Before:=oXLSheet.Range("A4")
' using this one:
oXLSheet.Rows(4).PageBreak = xlPageBreakManual
End With
'
Set oXLApp = Nothing
Set oXLBook = Nothing
Set oXLSheet = Nothing
End Sub
ASKER
Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.
TRUSTED BY
ASKER
I will get back to you.
Meanwhile:
I was wondering if the sequence matters.
Maybe page breaks should be inserted AFTER the spreadsheet is populated.
I'm guessing that changing the contents of a cell might negate other attributes.
I'm going to experiment.