Results 1 to 13 of 13

Thread: [RESOLVED] Print tray problems

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    8

    Resolved [RESOLVED] Print tray problems

    This is the macro I have to work with. It was written a decade ago. (Un)fortunately we are still using Word 2003 so only changes are the entire firm has moved to Windows 7 and the printers have changed. My problem is this: when I change a tray number(s) below, my save is ignored as if I didn't change a thing.

    For example, if below, I change the printer tray numbers from 259 to 261 for Jody's printer, nothing happens. I've created a little macro for myself to ensure I have the right tray numbers and I do, but no change happens, why? A lot of the printers shown below don't exist anymore but Jody's does and it has the right address, so....?

    Case "\\ServerName\PR_JODY"
    With Selection.PageSetup
    .FirstPageTray = 259
    .OtherPagesTray = 259
    End With

    Sub PrintFinal()
    Selection.HomeKey Unit:=wdStory
    ActiveWindow.ActivePane.View.Type = wdPrintView
    EachSection:
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    ActiveWindow.View.ShowFieldCodes = True
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "grabthisdocument.doc"
    .Replacement.Text = "grabthatdocument.doc"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.WholeStory
    Selection.Fields.Update
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    ActiveWindow.View.ShowFieldCodes = False
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "www.domainname.com"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .Execute
    If .Found = True Then
    Selection.Font.Hidden = True
    End If
    End With
    With Selection.PageSetup
    .DifferentFirstPageHeaderFooter = False
    End With
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "www.domainname.com"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .Execute
    If .Found = True Then
    Selection.Font.Hidden = True
    End If
    End With
    ActiveWindow.View.ShowFieldCodes = True
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "Page2grabthisdocument.doc"
    .Replacement.Text = "Page2grabthatdocument.doc"
    .Format = False
    .Forward = True
    .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.WholeStory
    Selection.Fields.Update
    With Selection.PageSetup
    .DifferentFirstPageHeaderFooter = True
    End With
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    'Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
    ' With Selection.Borders(wdBorderTop)
    ' .LineStyle = Options.DefaultBorderLineStyle
    ' .LineWidth = Options.DefaultBorderLineWidth
    ' .Color = Options.DefaultBorderColor
    ' End With
    'Tray 1 and 2 - Letterhead and 2nd Sheet
    Select Case Left(ActivePrinter, 11)
    Case "PrinterNameLocationandName"
    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = 259
    End With
    Case "PrinterNameLocationandName1"
    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = 259
    End With
    Case "\\XP130\HP5"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterLowerBin
    End With
    Case "PrinterNameLocationandName2"
    With Selection.PageSetup
    .FirstPageTray = 257
    .OtherPagesTray = 257
    End With
    GoTo continue
    Case "PrinterNameLocationandName3"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "\\XP105\HPL"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterNameLocationandName4"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "\\XP30\HP23"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterNameLocationandName5"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterNameLocationandName6"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterNameLocationandName7"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterNameLocationandName8"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterNameLocationandName9"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterNameLocationandName10"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterNameLocationandName11"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterNameLocationandName12"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterNameLocationandName13"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterLowerBin
    End With
    Case "PrinterNameLocationandName14"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName15"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName16"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName17"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName18"
    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = 259
    End With
    Case "PrinterNameLocationandName19"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "\PrinterNameLocationandName20"
    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = 259
    End With
    Case "PrinterNameLocationandName21"
    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName22"
    With Selection.PageSetup
    .FirstPageTray = 259
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName23"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterLowerBin
    End With
    Case Else
    End Select
    Select Case UCase(Left(ActivePrinter, 17))
    Case "PrinterNameLocationandName24"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName25"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName26"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName27"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName28"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName29"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName30"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterNameLocationandName31"
    With Selection.PageSetup
    .FirstPageTray = 259
    .OtherPagesTray = 259
    End With
    Case "PrinterNameLocationandName32"
    With Selection.PageSetup
    .FirstPageTray = 259
    .OtherPagesTray = 259
    End With
    Case Else
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    End Select
    continue:
    ActiveWindow.View.ShowFieldCodes = False
    With ActiveDocument.Styles("Header").ParagraphFormat
    .SpaceAfter = 0
    End With
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "^b"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
    If .Found = True Then
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    GoTo EachSection
    End If
    End With
    Dialogs(wdDialogFilePrint).Show
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Print tray problems

    are you sure that the correct code is running to set the printer trays?
    some of the cases possibly can never match the selected case value of activeprinter

    please edit you post to enclose the code in code tags to make it more readable, repaste the code if need be to make sure indenting is retained
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    8

    Re: Print tray problems

    Well, I did try that, and I'm new to this forum, but the preview shows my "tabbing" didn't stick. Can I attach a Word document with the code properly displayed?

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    8

    Re: Print tray problems

    I think I got it. I'll post the correct indenting

  5. #5
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: Print tray problems

    Quick glance you are using Select Case Left(ActivePrinter, 11) but the printer names are longer than 11 characters.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Print tray problems

    code tags are
    [/code] your code [code]
    i have them in reverse order, the / goes after the code, else you would not see them
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    8

    Re: Print tray problems

    Sub PrintFinal()
    Selection.HomeKey Unit:=wdStory
    ActiveWindow.ActivePane.View.Type = wdPrintView
    EachSection:
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    ActiveWindow.View.ShowFieldCodes = True
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "OldTemplate.doc"
    Replacement.Text = "NewTemplate.doc"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.WholeStory
    Selection.Fields.Update
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    ActiveWindow.View.ShowFieldCodes = False
    Selection.Find.ClearFormatting
    With Selection.Find
    Text = "www.DomainName.com"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .Execute
    If .Found = True Then
    Selection.Font.Hidden = True
    End If
    End With
    With Selection.PageSetup
    .DifferentFirstPageHeaderFooter = False
    End With
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "www.DomainName.com"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .Execute
    If .Found = True Then
    Selection.Font.Hidden = True
    End If
    End With
    ActiveWindow.View.ShowFieldCodes = True
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    Text = "OldTemplatePage2.doc"
    .Replacement.Text = "NewTemplatePage2.doc"
    .Format = False
    .Forward = True
    .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.WholeStory
    Selection.Fields.Update
    With Selection.PageSetup
    [Indent]
    .DifferentFirstPageHeaderFooter = True
    End With
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    '
    Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
    '
    With Selection.Borders(wdBorderTop)
    '
    .LineStyle = Options.DefaultBorderLineStyle
    '
    .LineWidth = Options.DefaultBorderLineWidth
    '
    .Color = Options.DefaultBorderColor
    '
    End With
    '
    Tray 1 and 2 - Letterhead and 2nd Sheet
    Select Case Left(ActivePrinter, 11)
    Case "PrinterLocationAndName0"
    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = 259
    End With
    Case "PrinterLocationAndName2"
    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = 259
    End With
    Case "\\ServerName\PR_Jody"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterLowerBin
    End With
    Case "PrinterLocationAndName4"
    With Selection.PageSetup
    .FirstPageTray = 257
    .OtherPagesTray = 257
    End With
    GoTo continue
    Case "PrinterLocationAndName5"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName6"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName7"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName8"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName9"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName10"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName11"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName9"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName10"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName11"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName12"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName13"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End With
    Case "PrinterLocationAndName14"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterLowerBin
    End With
    Case "PrinterLocationAndName15"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName16"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName17"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName18"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName19"
    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = 259
    End With
    Case "PrinterLocationAndName20"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName21"
    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = 259
    End With
    Case "PrinterLocationAndName22"
    With Selection.PageSetup
    .FirstPageTray = 258
    .OtherPagesTray = 260
    End With

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    8

    Re: Print tray problems

    Case "PrinterLocationAndName23"
    With Selection.PageSetup
    .FirstPageTray = 259
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName24"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterLowerBin
    End With
    Case Else
    End Select
    Select Case UCase(Left(ActivePrinter, 17))
    Case "PrinterLocationAndName25"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName26"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName27"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName28"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName29"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName30"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName31"
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    Case "PrinterLocationAndName32"
    With Selection.PageSetup
    .FirstPageTray = 259
    .OtherPagesTray = 259
    End With
    Case "\\PrinterLocation\PR_JODY"
    With Selection.PageSetup
    .FirstPageTray = 259
    .OtherPagesTray = 259
    End With
    Case Else
    With Selection.PageSetup
    .FirstPageTray = 261
    .OtherPagesTray = 260
    End With
    End Select
    continue:
    ActiveWindow.View.ShowFieldCodes = False
    With ActiveDocument.Styles("Header").ParagraphFormat
    .SpaceAfter = 0
    End With
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "^b"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
    If .Found = True Then
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    GoTo EachSection
    End If
    End With[/Indent]
    Dialogs(wdDialogFilePrint).Show
    End Sub

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    8

    Re: Print tray problems

    The code was too long to post in one shot. With respect to the printer names, I've changed most of them to "PrinterLocationAndName[]", but PR_Jody and PR_Mandy do exist and it is this format and average length that the printer names appear in the original code...so are the printer names still too long?

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Print tray problems

    Select Case Left(ActivePrinter, 11)

    Case "\\ServerName\PR_Jody"
    With Selection.PageSetup
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterLowerBin
    End With
    as mentioned by dmacura (and hinted at by me previously) this case (and many others), longer than 11 characters will never match left(activeprinter, 11), so the code will never run, put a breakpoint to test it

    either change to
    select case activeprinter
    to use the full names
    or cut all the cases to 11 characters
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    8

    Re: Print tray problems

    Thank you! I will try that. By the way, is there a benefit to restricting the character length?

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Print tray problems

    is there a benefit to restricting the character length?
    i doubt it in this case, but assume, it was done originally, for some good reason
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    8

    Re: Print tray problems

    Thanks, that solved the problem!

Posting Permissions

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



Click Here to Expand Forum to Full Width