Results 1 to 9 of 9
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Printer select (WXP MSO2003)

    Hi

    We have a bunch of users who insist on changing their default printers all the time. To ensure they print our reports on the correct paper I have developed a macro to check what printer is active and then set the paper trays to suit.

    Can anyone tell me what is wrong with the following? The macro ensures goes to the start of the report, sets the first page, goes to the next section (page) and sets that page and subsequent pages.

    What I am finding is that it goes to the ActivePrinter line and then skips over the code?????????

    Sub Printerselect()

    Selection.HomeKey Unit:=wdStory

    If Application.ActivePrinter = "IANZDEVHP LaserJet 4200 PS" Then

    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = wdPrinterDefaultBin
    End With

    Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=2, Name:=""

    With Selection.PageSetup
    .FirstPageTray = 257
    .OtherPagesTray = 259
    End With
    Else
    If Application.ActivePrinter = "ApolloAS 4250 PS" Then

    With Selection.PageSetup
    .FirstPageTray = 260
    .OtherPagesTray = 261
    End With

    Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=2, Name:=""

    With Selection.PageSetup

    .FirstPageTray = 259
    .OtherPagesTray = 261

    End With
    End If
    End If


    End Sub
    cheers

    Phil Carter

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Printer select (WXP MSO2003)

    Activate the Visual Basic Editor (Alt+F11)
    Activate the Immediate window (Ctrl+G)
    Type ? Application.ActivePrinter and press Enter.
    Does the displayed name exactly equal either IANZDEVHP LaserJet 4200 PS or ApolloAS 4250 PS ?

  3. #3
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: Printer select (WXP MSO2003)

    Hans thanks for that

    This is what returns: IANZDEVHP LaserJet 4200 PS on NE07:

    Do I need to specify the port?

    cheers
    cheers

    Phil Carter

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Printer select (WXP MSO2003)

    Not if you change your If statement to
    If InStr(ActivePrinter, "IANZDEVHP LaserJet 4200 PS") > 0 Then
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: Printer select (WXP MSO2003)

    Andrew thank you

    That worked just fine.

    What is the of the InStr statement?

    Sorry about the sports results (except the cricket of course) last week!
    cheers

    Phil Carter

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Printer select (WXP MSO2003)

    Thats OK with the sports results - I'm in Melbourne so the league and union don't make it into the papers often down here.

    The InStr function is looking to see whether the string you provide is contained within the ActivePrinter value. You were trying to compare only part of the returned ActivePrinter value with the actual value so it was either a case of including the port information or just looking to see whether there was any commonality.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #7
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: Printer select (WXP MSO2003)

    Andrew thanks again

    Very clear and concise as usual

    cheers
    cheers

    Phil Carter

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Printer select (WXP MSO2003)

    What happens when you single step the code?
    If I put in the name of my Activeprinter then it appears to execute OK.

    I am a bit confused by the line
    <code>Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=2, Name:=""</code>

    If you are going to the First section then Count:=2 makes no sense. You usually use Count with Which:=wdGoToAbsolute (or wdGoToPrevious or wdGoToNext)

    regards,

    StuartR

  9. #9
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: Printer select (WXP MSO2003)

    Stuart

    Thanks for replying.

    The first line of the routine moves to the beginning of the document (section1), this line moves to section 2 after setting the printer trays for section 1. This code was generated by creating a macro and stepping through the EditGoto menu selection.

    cheers
    cheers

    Phil Carter

Posting Permissions

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