Consulting

Results 1 to 6 of 6

Thread: Print Macro

  1. #1
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location

    Print Macro

    Good day all,

    I have a print macro that works wonderfully except when my dialog box appears to give the user a printer option and he or she clicks cancel the job prints regardless. How do I get the job to not print when the user cancels out of the printer dialog box?

    [vba]Sub PrintReports()


    'Turn screen updating off
    Application.ScreenUpdating = False

    'select printer
    Application.Dialogs(xlDialogPrinterSetup).Show

    'unhide sheets
    Dim wsSheet As Worksheet
    For Each wsSheet In ActiveWorkbook.Worksheets
    wsSheet.Visible = xlSheetVisible
    Next wsSheet

    'Print workbook
    ActiveWorkbook.PrintOut Copies:=1, Collate:=True

    'Turn screen updating back on
    Application.ScreenUpdating = True
    End Sub

    [/vba]

    As always, much gratitude!

    Cheers!
    tóg(a'í) go réidh é!

    Cheers!

  2. #2
    VBAX Regular Chabu's Avatar
    Joined
    Dec 2010
    Location
    Brussels
    Posts
    85
    Location
    The dialog returns a boolean that is False if the user clicks the cancel button and True if OK.
    [VBA] Dim x As Boolean
    'select printer
    x = Application.Dialogs(xlDialogPrinterSetup).Show[/VBA]

    put the rest of the code in an IF block

  3. #3
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    That makes sense, thanks.

    My only problem is placing the syntax properly.
    tóg(a'í) go réidh é!

    Cheers!

  4. #4
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    Bump.

    If possible, I'd appreciate assistance with the correct syntax for my dilemma. Help much welcomed!
    tóg(a'í) go réidh é!

    Cheers!

  5. #5
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    Since I can't delete a post I'll redact it; I think I have it figured. Thanks!
    tóg(a'í) go réidh é!

    Cheers!

  6. #6
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    [vba]Sub PrintReports()

    'Turn screen updating off
    Application.ScreenUpdating = False

    Dim x As Boolean
    'select printer
    x = Application.Dialogs(xlDialogPrinterSetup).Show

    If x = True

    'unhide sheets
    Dim wsSheet As Worksheet
    For Each wsSheet In ActiveWorkbook.Worksheets
    wsSheet.Visible = xlSheetVisible
    Next wsSheet

    'Print workbook
    ActiveWorkbook.PrintOut Copies:=1, Collate:=True

    End If

    'Turn screen updating back on
    Application.ScreenUpdating = True
    End Sub

    [/vba]

Posting Permissions

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