Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: How to Change the Paper Source Using the SendKeys Command


View products that this article applies to.

Summary

It is possible to change the default paper source used by printer drivers in Microsoft Windows Windows 95 and later versions of Windows by using the SendKeys command within a Visual Basic for Applications subroutine in Microsoft Excel 2000.

NOTE: 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 and later.

↑ Back to the top


More information

Microsoft provides programming examples 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 article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS
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 can use the following command:
SendKeys "%ha"
				
In this example, "%h" is equivalent to pressing ALT+H, which starts the Help menu. The "a" is equivalent to selecting the About Microsoft Excel menu item.

You can change the paper source used by a printer driver in Windows 95 or later 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 that 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 that you will always be switching to a particular paper source, you do not have to use the xSource variable. For example, the following command always switches to the Manual Feed paper source setting:
SendKeys "%fu%o%sm~~"
				

↑ Back to the top


Keywords: KB213815, kbprogramming, kbprint, kbhowto, kbdtacode

↑ Back to the top

Article Info
Article ID : 213815
Revision : 8
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 321