Consulting

Results 1 to 7 of 7

Thread: Solved: Print problem

  1. #1

    Solved: Print problem

    Hi,

    I used the macro recorder to set the print up on a 17 sheet workbook as below. Problem is after it prints the sheets it debugs 'printout method of worksheet class failed'. Any ideas what I need to fix? Also I have named the first sheet 'SUMMARY' and would like this to 'page fit' on portrait - but include this in the same routine.

    Sub checkprintsettings()

    Application.ScreenUpdating = False

    For Each sht In Worksheets
    sht.Activate
    With ActiveSheet.PageSetup
    .PrintGridlines = True
    .Orientation = xlLandscape
    .Zoom = 87

    ActiveSheet.PrintOut copies:=1, Collate:=True

    End With

    Next sht

    End Sub


    Many thanks

    Jon

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Don't know about the error, I don't get it, but for the portrait print

    [vba]

    Sub checkprintsettings()
    Dim sht As Worksheet

    Application.ScreenUpdating = False

    For Each sht In Worksheets
    With sht.PageSetup
    .PrintGridlines = True
    If sht.Name = "SUMMARY" Then
    .Orientation = xlPortrait
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    Else
    .Orientation = xlLandscape
    .Zoom = 87
    End If

    sht.PrintPreview 'Out copies:=1, Collate:=True
    End With
    Next sht

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks for help XLD - when I do this in test with just 3 sheets and very little other code it works fine. However when I copy to my project which has lots of modules/functions/user forms it still gives me the debug error.
    Project too big to post as its 700Kbs - can only assume theres something in there thats causing the problem. I'll just ask users to use the 'end' button on the debug as it does actually print everything.

    thanks again

    regards

  4. #4
    There is a hidden sheet - could this be the problem? If so how can I tell the print macro tho ignore any hidden sheets?

    thanks

  5. #5
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,288
    Location
    ?[VBA]Sub checkprintsettings()
    Dim sht As Worksheet
    Application.ScreenUpdating = False
    For Each sht In Worksheets
    'Additional check
    If sht.Visible = xlSheetVisible Then
    With sht.PageSetup
    .PrintGridlines = True
    If sht.Name = "SUMMARY" Then
    .Orientation = xlPortrait
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    Else
    .Orientation = xlLandscape
    .Zoom = 87
    End If
    sht.PrintPreview 'Out copies:=1, Collate:=True
    End With
    End If
    Next sht
    End Sub[/VBA]

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub checkprintsettings()
    Dim sht As Worksheet

    Application.ScreenUpdating = False

    For Each sht In Worksheets
    IF sht.Visible = xlSheetVisible Then
    With sht.PageSetup
    .PrintGridlines = True
    If sht.Name = "SUMMARY" Then
    .Orientation = xlPortrait
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    Else
    .Orientation = xlLandscape
    .Zoom = 87
    End If

    sht.PrintPreview 'Out copies:=1, Collate:=True
    End If
    End With
    Next sht

    End Sub
    [/vba]

    _________________________________________
    UK Cambridge XL Users Conference 29-30 Nov
    http://www.exceluserconference.com/UKEUC.html
    Last edited by Bob Phillips; 11-23-2007 at 06:00 AM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Guys - thanks for your help - works fine both ways.

    regards

    Jon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •