SYMPTOMS
In the programs that are listed in the "Applies to" section, when you use the Shell function in a Microsoft Visual Basic for
Applications (VBA) macro to execute an external MS-DOS call, if you use
commands contained only in the MS-DOS core, you receive the following
error message:
Invalid Procedure Call
The commands that return this error message are the following:
DIR, CLS, DEL, CD, MD, RD, MKDIR, RMDIR, COPY
WORKAROUND
To work around this problem, perform the commands that cause the error
message by using the equivalent VBA commands.
You can perform most of the functions that are provided by Command.com
through commands that are included in VBA. Some common core MS-DOS commands and their VBA
equivalents are listed below.
MS-DOS command Microsoft VBA command
-----------------------------------------------------------------------
DEL [drive][path]filename Kill "[drive][path]filename"
CD [drive][path] ChDir "[drive][path]"
MD [drive][path]directory name MkDir "[drive][path]directory name"
RD [drive][path]directory name RmDir "[drive][path]directory name"
COPY [source] [destination] FileCopy "[source]","[destination]"
DIR [path] Dir("[path]",[attributes])
Note The Visual Basic for Applications Dir command does not function
identically to its MS-DOS equivalent, and requires extra code to
retrieve an entire directory.
For more information about the Dir command in Visual Basic for
Applications, click the Index tab in Microsoft Excel Help or in Microsoft Access Help, type the
following text
and then double-click the selected text to go to the "Dir function"
topic.
In cases where it is absolutely essential to use one of the MS-DOS core
commands, it is possible to invoke an instance of the command
interpreter manually and pass it the desired command. To do this, use
the following syntax:
a = Shell("command.com /c [command]", [WindowStyle])
Note You must include /c for the command to be executed correctly. For
example, to perform a directory command of all hidden files in the root
directory, use the following syntax:
Shell("command.com /c dir c:\ /ah", 1)