Consulting

Results 1 to 3 of 3

Thread: Solved: Print Preview

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location

    Solved: Print Preview

    Hello all,
    Is there a way to print preview a hidden sheet? My code below works if I set the sheet to visible but doesn't work if the sheet remains hidden.

    [vba]
    Sub PrintBothPlatoonsMain()

    Dim ThisSheet As Worksheet
    Set ThisSheet = ActiveSheet

    Application.ScreenUpdating = False
    Application.EnableEvents = False

    Module1.DoProtect False
    Sheets("Both Platoons").Visible = True
    Call BothPlatoonsSheet
    Call PrintSetupForBothPlatoons
    Call PrintPreview
    Sheets("Both Platoons").Visible = False
    'Call PrintCopies
    Module1.DoProtect True

    ThisSheet.Activate
    Application.ScreenUpdating = True
    Application.EnableEvents = True


    End Sub

    [/vba]
    [vba]
    Sub PrintSetupForBothPlatoons()
    Dim LastRow As Long
    Sheets("Both Platoons").Activate
    'Find The Last Row On The Worksheet
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row

    With ActiveSheet.PageSetup
    .Orientation = xlLandscape
    .CenterVertically = True
    .LeftMargin = Application.InchesToPoints(1.06)
    .RightMargin = Application.InchesToPoints(0)
    .PaperSize = xlPaperLegal
    .PrintArea = "$A$1:$AF" & LastRow
    .Zoom = 93
    '.Zoom = False
    '.FitToPagesWide = 1
    End With
    End Sub
    [/vba]

    [VBA]
    Sub PrintPreview()
    'Preview Sheet
    ' ActiveWindow.SelectedSheets.PrintPreview
    ' ActiveWindow.PrintPreview
    ActiveSheet.PrintPreview
    End Sub


    [/VBA]
    Thanks
    Gary

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    836
    Location
    A gift to me from Anne originally. HTH. Dave
    [vba]
    With Sheets("Both Platoons")
    LastRow = .Cells(.Cells.Rows.Count, "A").End(xlUp).Row()
    End With
    [/vba]ps. I think this should also work...
    [vba]
    LastRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row()

    [/vba]
    On edit I see that this isn't actually your area of difficulty... but your syntax does look off. Anyways, I'll leave this post and thread bump to hopefully get you some help. Where's this sub "BothPlatoonsSheet" anyways?
    Last edited by Dave; 06-01-2009 at 10:35 PM.

  3. #3
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location
    Well I found several references to printing hidden sheets on the net and they all say you have to unhide the sheet before printing.
    By the way Dave, I am not experiencing any problems with the lastrow line I just wanted to print preview a hidden sheet without unhiding it.


    Thanks anyway
    Gary

Posting Permissions

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