XL: Shell Function Doesn't Accept Built-in ConstantsLast reviewed: September 2, 1997Article ID: Q113631 |
The information in this article applies to:
SUMMARYIn Microsoft Excel version 5.0 for Windows, it is not possible to use built- in constants, such as xlNormal, xlMinimized, or xlMaximized, for the "windowstyle" argument of the Visual Basic Shell function. This behavior is by design.
MORE INFORMATIONThe Visual Basic Shell function is used to run an executable program from a Visual Basic subroutine. Here is an example of the Shell function that will run the Microsoft Windows Notepad program in a normal window with focus:
RetVal = Shell("c:\windows\notepad.exe", 1)The second argument (in this case, 1) is the windowstyle argument of the function. Valid windowstyle values are as follows:
Value Window Style --------------------------------- 1, 5, 9 Normal with focus 2 Minimized with focus 3 Maximized with focus 4, 8 Normal without focus 6, 7 Minimized without focusThe windowstyle you specify determines how the application's window will appear when it is started. It is not possible to use built-in constants such as xlNormal, xlMinimized, or xlMaximized in place of the standard numerical values shown here. This is because the values of the built-in constants are not valid when applied to the Shell command. The values of the various built-in constants that might be expected to work as windowstyle arguments are as follows:
Constant Value ------------------- xlNormal -4143 xlMinimized -4140 xlMaximized -4137If you try to use a built-in constant for the windowstyle argument, you will receive the following error message:
Run-time error '5': Invalid procedure call Steps to Reproduce BehaviorMicrosoft 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. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line continuation character. For more information about Visual Basic for Applications programming style, see the "Programming Style in This Manual" section in the "Document Conventions" section of the "Visual Basic User's Guide." The following examples illustrate proper, and improper, use of the windowstyle argument in the Shell function.
'----------------------------------------------------------------------Option Explicit
Sub ProperShellFunction() 'Dimension variables. Dim RetVal As Double 'This Shell function will work because the windowstyle argument is 'valid (1). RetVal = Shell("c:\windows\notepad.exe", 1) End Sub Sub ImproperShellFunction() 'Dimension variables. Dim SecondRetVal As Double 'This Shell function will NOT work because the windowstyle argument 'is invalid (cannot use this built-in constant in this case). SecondRetVal = Shell("c:\windows\notepad.exe", xlNormal) End Sub '---------------------------------------------------------------------- REFERENCESFor more information on the Shell function, choose the Search button in Visual Basic Help and type:
Shell |
Additional query words: 5.00 5.00c 7.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |