PRJ: Error Using Command Without Required Arguments

ID: Q113272

The information in this article applies to:

SYMPTOMS

In Microsoft Project, when you run a macro that contains a command that is missing required arguments, you receive the following error message:

   Argument not optional

Additionally, if you assign macro command to a toolbar without required arguments, you receive the following error message:

   Required argument not included

CAUSE

This behavior is by design in Microsoft Project. When you use a command in a macro, or assign a command to a toolbar button, you must include required arguments with the command.

One exception to this rule is a command that displays a dialog box, such as FileOpen. When you use a command that displays a dialog box, you do not necessarily need to include arguments, even if they are described as required in the Visual Basic Reference. If the help topic for the command states that the command displays a dialog box, you can use the command without arguments to display the dialog box.

WORKAROUNDS

If you want to prompt a user for input, and use this input as an argument for a macro command that does not display a dialog box, you can use the InputBox function to store information from the user as a variable, then use the variable as the value of the required argument. The following is a simple example of how to use this method:

   Sub Edit_View()
      ' Dimension variables
      Dim ViewName, ViewTable, ViewFilter As String
      ' Prompt user for view to edit
      ViewName = InputBox("Type name of single-pane view to edit")
      ' Prompt user for table to apply
      ViewTable = InputBox("Type name of table to apply to view")
      ' Prompt user for filter to apply
      ViewFilter = InputBox("Type name of filter to apply to view")
      ViewEditSingle Name:=ViewName, Table:=ViewTable, _
         Filter:=ViewFilter
   End Sub

Note that the macro example would need to have error checking procedures to test for valid user input.

Microsoft 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.

MORE INFORMATION

When you record a macro in Microsoft Project, and you choose an option in a dialog box that displays another dialog box, the command recorded usually does not display that second dialog box. There are some commands that are "non- interactive" meaning they are designed only to record complex dialog boxes, but there is no command to display them directly.

For example, if you turn on the macro recorder and edit a filter, by first displaying the More Filters dialog box, then choosing Edit to display the Filter Definition dialog box, the EditFilter command is recorded with all of the EditFilter arguments. If you use the EditFilter command by itself in a macro however, you receive the error message described above because the EditFilter command does not display a dialog box.

On the other hand, if you turn on the macro recorder and open a file, by displaying the Open dialog box, the FileOpen command is recorded with each of the parameters following the command. If you use the FileOpen command in a macro without any arguments, the FileOpen dialog box is displayed.

For a list of the arguments required for a specific command when you use the command in a macro, select the command in the macro you are editing and press F1. The help topic for that command appears, with a description of all arguments and the word Optional or Required.

Steps to Reproduce Behavior

1. In a new project, hold down the CTRL key, and click the Standard

   Toolbar.

2. In the Customize Tool dialog box, select GanttBarStyleEdit from the
   Command list. Choose OK.

   The following error message appears:

      Required argument not included

Additional query words: 4.00 vbappcode
Keywords          : kbcode kbprg
Version           : 4.0 4.1 98
Platform          : MACINTOSH WINDOWS

Last Reviewed: November 25, 1997