简体   繁体   English

Excel-附加到窗体控制按钮的宏未激活

[英]Excel - macro attached to form Control Button not activating

I have an odd issue with a single command button refusing to run the macro attached. 我有一个奇怪的问题,一个命令按钮拒绝运行附加的宏。 I get the message "Cannot run the macro "". The macro may not be available in this workbook or all macros may be disabled." 我收到消息“无法运行宏”,该宏可能在此工作簿中不可用,或者可能禁用了所有宏。

I have three buttons created by code on a new sheet and the macros assigned. 我在新工作表上通过代码创建了三个按钮,并分配了宏。 The first two buttons work perfectly but the third does not. 前两个按钮可以正常工作,而第三个则不能。 If I re-assign the same macro to the button (right click - assign macro) it works fine but this will not accomplish what I need. 如果我将相同的宏重新分配给按钮(右键单击-分配宏),则可以正常工作,但这将无法实现我所需要的。

All macros etc have been enabled. 所有宏等已启用。 I hope someone can help, this is doing my head in! 希望有人能提供帮助,这是我的努力!

    Sub AddButton()

    Dim ButtonName1, ButtonName2, ButtonName3 As String

    ActiveSheet.Buttons.Add(200, 5, 81, 36).Select
    ButtonName1 = Selection.Name
    Selection.OnAction = "CopyBack"
    ActiveSheet.Shapes(ButtonName1).TextFrame.Characters.Text = "Modify Scenario (Copy back)"

    ActiveSheet.Buttons.Add(285, 5, 81, 36).Select
    ButtonName2 = Selection.Name
    Selection.OnAction = "GotoPlanner"
    ActiveSheet.Shapes(ButtonName2).TextFrame.Characters.Text = "Return To Shift Planner"

    ActiveSheet.Buttons.Add(370, 5, 81, 36).Select
    ButtonName3 = Selection.Name
    Selection.OnAction = "DellCurrSheet"
    ActiveSheet.Shapes(ButtonName3).TextFrame.Characters.Text = "Delete This Scenario"

    ActiveSheet.Range("A1").Select

    End Sub

抱歉,如果我在此上浪费了任何人的时间,但是我发现了造成宏名称分配问题的错字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM