OFF2000: CommandBar Indexes Different from Office 97 (215149)
The information in this article applies to:
- Microsoft Excel 2000
- Microsoft Access 2000
- Microsoft PowerPoint 2000
- Microsoft Word 2000
This article was previously published under Q215149 SYMPTOMS
When you run a Visual Basic macro that adds or manipulates toolbar buttons or menu commands for the CommandBars object, the controls may be added to a different CommandBar, or an error message similar to the following may appear:
Run-time error '5':
Invalid procedure call or argument
CAUSE
This problem will occur when you use the CommandBars object and refer to a the control index rather than by name. For example, this problem will ocur if you refer to the index for the worksheet shortcut menu instead of its name "Cell."
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.
When the following examples are run in Excel, you will receive the error mentioned in the Symptoms section.
Sub NewCommand()
Set x = CommandBars(21).Controls.Add(Type:=msoControlButton)
x.Caption = "hello"
End Sub
Sub ChangeCaption()
CommandBars(21).Controls.Caption = "Hello world"
End Sub
RESOLUTION
To successfully work with the CommandBars object and its controls between Office 97 and Office 2000 programs, you must reference the CommandBar controls by their name instead of by their index numbers. See the "More Information" section for a list of Office 97 index numbers and their respective names in Office 2000.
REFERENCESFor more information about CommandBars, click Microsoft Excel Help on the Help menu, type CommandBar Object in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbdtacode kberrmsg kbprb KB215149 |
---|
|