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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Automation - Pages Added

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,971
US
Why would the following code be adding blank pages to my Excel document when I view it in Print Preview? When I comment out the calls in red everything is as it should be. Any ideas? Thanks.

Code:
    With oXLSheet
        .Rows("1:1").RowHeight = 48
        .Rows("2:2").RowHeight = 26.25
        .Rows("3:5").RowHeight = 15.75
        .Rows("6:6").RowHeight = 12.75
        .Rows("7:26").RowHeight = 18
        .Rows("27:74").RowHeight = 12.75
        .Rows("75:75").RowHeight = 21
        .Rows("76:79").RowHeight = 12.75
        .Rows("80:85").RowHeight = 18
        .Rows("86:65536").RowHeight = 12.75
        .Columns("A:A").ColumnWidth = 15.14
        .Columns("B:B").ColumnWidth = 7.14
        .Columns("C:C").ColumnWidth = 7.86
        .Columns("D:D").ColumnWidth = 10
        .Columns("E:E").ColumnWidth = 11.71
        .Columns("F:G").ColumnWidth = 13.14
        .Columns("H:I").ColumnWidth = 12.86
        .Columns("J:J").ColumnWidth = 12
        .Columns("K:K").ColumnWidth = 12.29
        InsertPictureInRange App.Path & "\ABIS Logo.jpg", .Range("I1:K2")
        InsertPictureInRange App.Path & "\ABIS Logo.jpg", .Range("I71:K75")
    End With

Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
' inserts a picture and resizes it to fit the TargetCells range
Dim p As Object, t As Double, l As Double, w As Double, h As Double
    If TypeName(oXLSheet) <> "Worksheet" Then Exit Sub
    If Dir(PictureFileName) = "" Then Exit Sub
    ' import picture
    Set p = oXLSheet.Pictures.Insert(PictureFileName)
    ' determine positions
    With TargetCells
        t = .Top
        l = .Left
        w = .Offset(0, .Columns.Count).Left - .Left
        h = .Offset(.Rows.Count, 0).Top - .Top
    End With
    ' position picture
    With p
        .Top = t
        .Left = l
        .Width = w
        .Height = h
    End With
    Set p = Nothing
End Sub

Swi
 
Strange. It seems that if I decrease the height and width by 1 everything is ok. That would mean that the logo is printing out of the pritable area and thus forcing additional pages however when viewing the additional pages there was nothing on them.

Code:
Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
' Inserts a picture and resizes it to fit the TargetCells range
Dim p As Object, t As Double, l As Double, w As Double, h As Double
    If TypeName(oXLSheet) <> "Worksheet" Then Exit Sub
    If Dir(PictureFileName) = "" Then Exit Sub
    ' Import picture
    Set p = oXLSheet.Pictures.Insert(PictureFileName)
    ' Determine positions
    With TargetCells
        t = .Top
        l = .Left
        w = .Offset(0, .Columns.Count).Left - .Left
        h = .Offset(.Rows.Count, 0).Top - .Top
    End With
    ' Position picture
    With p
        .Top = t
        .Left = l
        .Width = w [red]- 1[/red]
        .Height = h [red]- 1[/red]
    End With
    Set p = Nothing
End Sub

Swi
 



I you ALWAYS want EVERYTHING on one page, select the Page Scaling to Fit to 1 by 1

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
I actually do not want that because I have a lot of information on the spreadsheet.

Swi
 



what blank pages?

go into View > page preview and observe WHERE.

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top