Microsoft KB Archive/105878

From BetaArchive Wiki
Knowledge Base


Article ID: 105878

Article Last Modified on 10/11/2006



APPLIES TO

  • Microsoft Excel 5.0 Standard Edition



This article was previously published under Q105878

SUMMARY

In Microsoft Excel, you can use the following Visual Basic, Applications Edition, macros to change the paper source on the Hewlett-Packard (HP) LaserJet 4/4M to the lower tray.

Sample Macros

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

To send key commands to the Printer Setup dialog box, use the following code:

   Sub HP4_Paper_Source()
        Application.Wait Now + Timevalue("00:00:01")
        Application.ActivePrinter = "HP LaserJet 4/4M on LPT1:"
        SendKeys "%(f)(p)(r)%(s)%(s){pgup}{down}{down}
        {down}{down}~~~"
   End Sub
                

In order to use this Macro with a shortcut key, you must put a wait statement before the Application.ActivePrinter line. The wait may have to be adjusted depending on the system environment. For example, to make the macro wait one second, use the following line of code:

   Application.Wait Now + Timevalue("00:00:01")
                

The following is an explanation of the string used in the SendKeys function:

   This command       Performs this action
   ----------------------------------------------------

   %(f)(p)(r)         Chooses Printer Setup in the Print dialog
   %(s)               Chooses Setup in the Printer Setup dialog
   %(s)               Chooses Paper Source in the HP 4/4M Setup dialog
   {pgup}             Moves Paper Source selection up
   {down}             Moves Paper Source selection down
                

To set the paper source, and then set it back to Auto Select, use the following code:

   Sub HP4_Paper_Source()
      Application.Wait Now + TimeValue("00:00:01")
      Application.ActivePrinter = "HP LaserJet 4Si/4Si MX on LPT1:"
      SendKeys "%(f)(p)(r)%(s)%(s){pgup}{down}{down}{down}{down}~~~"
      Application.OnTime Now + TimeValue("00:00:08"), "setback"
      ' SendKeys "%(f)(p)(r)%(s)%(s){pgup}~~~"
   End Sub

    Sub setback()
      Application.Wait Now + TimeValue("00:00:01")
      Application.ActivePrinter = "HP LaserJet 4Si/4Si MX on LPT1:"
      SendKeys "%(f)(p)(r)%(s)%(s){pgup}~~~"
   End Sub
                

MORE INFORMATION

In the Printer Setup dialog box, there is no accelerator key combination that will directly select a paper source such as lower tray. Instead, the arrow key should be used to select from the list of available sources. For example, on the HP LaserJet 4/4M there are six possible choices for the paper source:

  • Auto Select
  • MP Tray
  • Paper Cassette
  • Manual Feed
  • Lower Cassette
  • Envelope Feeder

Because the current paper source selection is not known before execution of the macro, use the {pgup} command to select the first item in the Paper Source list. This will guarantee that Auto Select is chosen. Four DOWN ARROW keystrokes will select the lower cassette.

NOTE: This macro may work for other printers or may require a different sequence of keystrokes depending on the printer driver.

REFERENCES

"Visual Basic User's Guide," version 5.0, Chapter 6


Additional query words: print XL5

Keywords: kbprogramming KB105878