In Microsoft Office, when you use the
Shell function in a Visual Basic for Applications macro to execute an
external MS-DOS command, an MS-DOS window may open and you may receive the
following error message:
Specified COMMAND search
directory had
Too many parameters
The MS-DOS window is fully
functional and the command you were attempting to run from the macro can be
successfully run from the MS-DOS prompt. The commands that return this error
message are the following:
- DIR
- CLS
- DEL
- CD
- MD (MKDIR)
- RD (RMDIR)
- COPY
This behavior occurs if you have not used the
/c switch in the macro. The
/c switch is required to properly execute MS-DOS commands in a
Visual Basic for Application macro.
To resolve this behavior, add the
/c switch after command.com. For example to create a new directory
called mydir, use the following code in a macro:
Shell "command.com /c md c:\mydir"
Note the
/c switch after command.com.
You can perform most of the commands that are provided by
command.com through statements and functions included in Microsoft Visual Basic
for Applications. Some common core MS-DOS commands and their Microsoft Visual
Basic equivalent statements are listed below.
MS-DOS Visual Basic Statement/function
DEL Kill
CD ChDir
MD MkDir
RD RmDir
COPY FileCopy
DIR Dir
Note For the correct syntax to use each Visual Basic statement, look
up the statement in the Microsoft Visual Basic help. For example, to learn how
to use Kill, type
kill in the Answer Wizard and click
Search.