+ Reply to Thread
Results 1 to 3 of 3

Setting print area within macro

  1. #1
    TimMalone
    Guest

    Setting print area within macro

    I have the following macro to select a specific worksheet and print based on
    user input of worksheet name:

    Sub PrintWS()
    Dim ws As Worksheet
    Dim sName$

    On Error GoTo ErrorInPrintWS
    sName = InputBox("Enter worksheet name", "Print")
    If sName <> "" Then
    Set ws = Worksheets(sName)
    ws.PrintOut
    End If

    Exit Sub
    ErrorInPrintWS:
    Exit Sub
    End Sub

    I tried to alter it as follows to define a specific print range but was not
    successful.

    Sub PrintDeptArea()
    Dim ws As Worksheet
    Dim sName$

    On Error GoTo ErrorInPrintWS
    sName = InputBox("Enter worksheet name", "Print")
    If sName <> "" Then
    Set ws = Worksheets(sName)
    ActiveSheet.PageSetup.PrintArea = "$A$9:$R$74"
    ws.PrintOut
    End If

    Exit Sub
    ErrorInPrintWS:
    Exit Sub
    End Sub

    Can anyone help?
    Thanks,
    Tim



  2. #2
    Tom Ogilvy
    Guest

    Re: Setting print area within macro

    Sub PrintDeptArea()
    Dim ws As Worksheet
    Dim sName$

    On Error GoTo ErrorInPrintWS
    sName = InputBox("Enter worksheet name", "Print")
    If sName <> "" Then
    Set ws = Worksheets(sName)
    ws.PageSetup.PrintArea = "'" & ws.Name & "'!$A$9:$R$74"
    ' ws.PrintOut
    End If

    Exit Sub
    ErrorInPrintWS:
    Exit Sub
    End Sub

    --
    Regards,
    Tom Ogilvy


    "TimMalone" <[email protected]> wrote in message
    news:[email protected]...
    > I have the following macro to select a specific worksheet and print based

    on
    > user input of worksheet name:
    >
    > Sub PrintWS()
    > Dim ws As Worksheet
    > Dim sName$
    >
    > On Error GoTo ErrorInPrintWS
    > sName = InputBox("Enter worksheet name", "Print")
    > If sName <> "" Then
    > Set ws = Worksheets(sName)
    > ws.PrintOut
    > End If
    >
    > Exit Sub
    > ErrorInPrintWS:
    > Exit Sub
    > End Sub
    >
    > I tried to alter it as follows to define a specific print range but was

    not
    > successful.
    >
    > Sub PrintDeptArea()
    > Dim ws As Worksheet
    > Dim sName$
    >
    > On Error GoTo ErrorInPrintWS
    > sName = InputBox("Enter worksheet name", "Print")
    > If sName <> "" Then
    > Set ws = Worksheets(sName)
    > ActiveSheet.PageSetup.PrintArea = "$A$9:$R$74"
    > ws.PrintOut
    > End If
    >
    > Exit Sub
    > ErrorInPrintWS:
    > Exit Sub
    > End Sub
    >
    > Can anyone help?
    > Thanks,
    > Tim
    >
    >




  3. #3
    TimMalone
    Guest

    RE: Setting print area within macro

    Tom,
    Thanks! I works like a charm.

    "TimMalone" wrote:

    > I have the following macro to select a specific worksheet and print based on
    > user input of worksheet name:
    >
    > Sub PrintWS()
    > Dim ws As Worksheet
    > Dim sName$
    >
    > On Error GoTo ErrorInPrintWS
    > sName = InputBox("Enter worksheet name", "Print")
    > If sName <> "" Then
    > Set ws = Worksheets(sName)
    > ws.PrintOut
    > End If
    >
    > Exit Sub
    > ErrorInPrintWS:
    > Exit Sub
    > End Sub
    >
    > I tried to alter it as follows to define a specific print range but was not
    > successful.
    >
    > Sub PrintDeptArea()
    > Dim ws As Worksheet
    > Dim sName$
    >
    > On Error GoTo ErrorInPrintWS
    > sName = InputBox("Enter worksheet name", "Print")
    > If sName <> "" Then
    > Set ws = Worksheets(sName)
    > ActiveSheet.PageSetup.PrintArea = "$A$9:$R$74"
    > ws.PrintOut
    > End If
    >
    > Exit Sub
    > ErrorInPrintWS:
    > Exit Sub
    > End Sub
    >
    > Can anyone help?
    > Thanks,
    > Tim
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1