Excel 加载项未正常运行
Excel add-in Not Functioning Properly
我正在尝试创建一个 excel 加载项,它允许我为列中的所有条目添加前缀。
我想我找到了一些代码来执行此操作,但不幸的是,我不断收到一条错误消息,指出“该工作簿中可能没有该宏,或者所有宏都已被禁用。我已经尝试了所有建议的禁用方法安全设置。
我希望能够简单地 select 文本,使用插件,并为每一列添加一个前缀。干杯,非常感谢您对此进行调查!
代码如下:
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("Super Code").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 = "Super Code"
.Style = msoButtonCaption
.OnAction = "MyGreatMacro"
'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("Super Code").Delete
On Error GoTo 0
End Sub
Private Sub AddTextOnLeft()
'Updateby20131128
Dim Rng As Range
Dim WorkRng As Range
Dim addStr As String
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
addStr = Application.InputBox("Add text", xTitleId, "", Type:=2)
For Each Rng In WorkRng
Rng.Value = addStr & Rng.Value
Next
End Sub
对于您分配的 OnAction 'MyGreatMacro' 而不是 'AddTextOnLeft'
应该是
.OnAction = "AddTextOnLeft"
而不是
.OnAction = "MyGreatMacro"
我正在尝试创建一个 excel 加载项,它允许我为列中的所有条目添加前缀。
我想我找到了一些代码来执行此操作,但不幸的是,我不断收到一条错误消息,指出“该工作簿中可能没有该宏,或者所有宏都已被禁用。我已经尝试了所有建议的禁用方法安全设置。
我希望能够简单地 select 文本,使用插件,并为每一列添加一个前缀。干杯,非常感谢您对此进行调查!
代码如下:
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("Super Code").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 = "Super Code"
.Style = msoButtonCaption
.OnAction = "MyGreatMacro"
'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("Super Code").Delete
On Error GoTo 0
End Sub
Private Sub AddTextOnLeft()
'Updateby20131128
Dim Rng As Range
Dim WorkRng As Range
Dim addStr As String
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
addStr = Application.InputBox("Add text", xTitleId, "", Type:=2)
For Each Rng In WorkRng
Rng.Value = addStr & Rng.Value
Next
End Sub
对于您分配的 OnAction 'MyGreatMacro' 而不是 'AddTextOnLeft'
应该是
.OnAction = "AddTextOnLeft"
而不是
.OnAction = "MyGreatMacro"