我最近使用.vba for Excel 2010完成了一个程序。它包含两个用于数据输入的用户表单,并且在我执行的所有错误测试中完美运行。但是,当我将程序用作加载项时,我无法以任何方式运行任何用户表单。我已将userform .show例程映射到宏并尝试直接打开它,两者都给出了相同的错误。
结果: 运行时错误' 9':下标超出范围
有问题的用户形式是 UformDataEntry
有问题的宏是 Start_Data_Entry
以下代码位于宏中:
Sub Start_Data_Entry()
'Display DataEntry UserForm
UformDataEntry.Show Modal
End Sub
以下代码位于 ThisWorkbook 对象:
中Option Explicit
Dim cControl As CommandBarButton
Private Sub Workbook_AddinInstall()
On Error Resume Next 'Just in case
'Delete any existing menu item that may have been left.
Application.CommandBars("Worksheet Menu Bar").Controls("ICD10").Delete
'Add the new menu item and Set a CommandBarButton Variable to it
Set cControl = Application.CommandBars("Worksheet Menu Bar").Controls.Add
'Work with the Variable
With cControl
.Caption = "ICD10"
.Style = msoButtonCaption
.OnAction = "Start_Data_Entry"
'Macro stored in a Standard Module
End With
On Error GoTo 0
End Sub
Private Sub Workbook_AddinUninstall()
On Error Resume Next 'In case it has already gone.
Application.CommandBars("Worksheet Menu Bar").Controls("ICD10").Delete
On Error GoTo 0
End Sub