XL: Changing the Paper Source Using SendKeysLast reviewed: February 27, 1998Article ID: Q135791 |
The information in this article applies to:
SUMMARYIt is possible to change the default paper source used by printer drivers in Windows 95 by using the SendKeys command within a Visual Basic for Applications subroutine in Microsoft Excel versions 7.0 and 97. Note that the information in this article does not pertain to earlier versions of Microsoft Windows, because the dialog box layout in earlier versions of Windows is somewhat different from that used in Windows 95.
MORE INFORMATIONMicrosoft provides examples of Visual Basic for Applications 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400. The SendKeys command in Visual Basic for Applications allows you to simulate the pressing of keys while a macro is running. By using the correct combination of keystrokes, you can accomplish many tasks that are not possible through normal macro commands. For example, if you need a subroutine to display the "About Microsoft Excel" dialog box, you could use the following command:
SendKeys "%ha"In this example, "%h" is equivalent to pressing ALT+H, which activates the Help menu. The "a" is equivalent to selecting the "About Microsoft Excel" menu item. You can change the paper source used by a Windows 95 printer driver by using commands similar to the following:
'Use ONE of the following four lines of code to determine the paper 'source. If a different letter is required, set the value of xSource 'accordingly. xSource = "a" 'Auto Select xSource = "u" 'Upper Tray xSource = "m" 'Manual Feed xSource = "l" 'Lower Tray 'This line of code actually changes the paper source. SendKeys "%fu%o%s" & xSource & "~~"In the SendKeys command, the following actions are executed.
Action Equivalent to ----------------------------------------------------- %f ALT+F. Selects the File menu. u Chooses Page Setup. %o ALT+O. Selects the Options button. %s ALT+S. Selects the Paper Source list box. ~~ Presses ENTER twice to accept the changes.The xSource variable contains a letter that determines what paper source is used. Depending on the value you use (usually "a," "u," "m," or "l"), the SendKeys statement selects the appropriate paper source, and then simulates two presses of the ENTER key to accept the changes. If you know you will always be switching to a particular paper source, you don't have to use the xSource variable. For example, the following command will always switch to the Manual Feed paper source:
SendKeys "%fu%o%sm~~"For information on using SEND.KEYS with earlier versions of Microsoft Excel, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q69614 TITLE : Using SEND.KEYS() to Change Paper Source in Printer Setup |
Additional query words: 7.00 8.00 97 xl97 send.keys() application
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |