Results 1 to 9 of 9
  1. #1
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA SendKeys won't work twice (2002 SP-2)

    I have documents that have an envelope as the 1st page, with all the text pages following. Through VBA code, I am trying to get my printer (Canon i865) to take the envelopes from the automatic sheet feeder and the paper from the paper cassette.
    Using
    Regards,
    Peter

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VBA SendKeys won't work twice (2002 SP-2)

    A programmatic solution is indeed a challenge. Selecting paper trays in a macro cannot be generalized: each printer driver seems to do it differently. I would use the macro recorder to capture the specific trays that you need to assign, going through File>Page Setup..., and see if you can avoid using the Printer Properties dialog, since that is beyond the reach of the Word object model.

    You also might try changing the False to True in the first Sendkeys call. Not sure it will make the two play well together, but it's worth a try.

  3. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA SendKeys won't work twice (2002 SP-2)

    Tried recording macro, but the paper source isn't recorded.
    I have tried every combination of True & False. It needs True to print the Envelope, but the Pages part won't do anything regardless of True or False
    Using the Printer dialog may be beyond the reach of the Word object model, but SendKeys should still work. I'm perplexed.
    It does seem to be a focus thing, but how does one get the focus back onto a dialog?
    Regards,
    Peter

  4. #4
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA SendKeys won't work twice (2002 SP-2)

    You could try something like this, that works for the HP 4xxx laserjet family we use:

    Sub PrintDiff()
    Dim lFirst As Long
    Dim lOther As Long
    If Documents.Count > 0 Then 'Prevents error if no doc loaded
    With ActiveDocument.PageSetup
    lFirst = .FirstPageTray 'Preserve current values
    lOther = .OtherPagesTray
    .FirstPageTray = wdPrinterLowerBin 'Tray 2 with special paper
    .OtherPagesTray = wdPrinterDefaultBin 'Tray 3 with normal paper
    ActiveDocument.PrintOut
    .FirstPageTray = lFirst 'Restore saved values
    .OtherPagesTray = lOther
    End With
    End If
    End Sub

    Added later:
    If the doc is protected you shoult lift the protection before you change the trays the first time, reprotect before printout and repeat lifting and reprotecting around the second change of the trays.

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA SendKeys won't work twice (2002 SP-2)

    Jan, you're a gem.
    It works like a charm. I do a lot of Access coding but VBA for Word is a whole new ball game for me.
    Thanks heaps
    Regards,
    Peter

  6. #6
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA SendKeys won't work twice (2002 SP-2)

    An after thought. Would you know of a way to set the Printer default tray to the lower cassette?
    My thinking is that this wouldn't be possible, as it totally depends on the printer. I can do it with SendKeys, but I'm not too comfortable with that.
    Regards,
    Peter

  7. #7
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA SendKeys won't work twice (2002 SP-2)

    I never tested that myself. But I suppose you can use the same technique in a Sub that is executed when Word starts (e.g. in Sub Main in a module called AutoExec). You'll have to experiment a little with the values for .FirstPageTray and .OtherPagesTray, I think. However, be careful if you're using a network printer. It might cause unexpected effects for other users of that printer!

  8. #8
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA SendKeys won't work twice (2002 SP-2)

    Thanks Jan, but aren
    Regards,
    Peter

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

    Re: VBA SendKeys won't work twice (2002 SP-2)

    Can you create a second printer driver to the same printer and alter the second one's tray setting?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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