Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 弹出窗口中的代码不会影响工作表元素_Excel_Vba_Popup_Commandbar - Fatal编程技术网

Excel 弹出窗口中的代码不会影响工作表元素

Excel 弹出窗口中的代码不会影响工作表元素,excel,vba,popup,commandbar,Excel,Vba,Popup,Commandbar,我正在尝试创建弹出菜单,它将提供从名为“元素”(椭圆形+文本框)的形状组复制粘贴形状对象的选项。 但似乎选择粘贴方法不起作用 Public Element_Menu As CommandBar Function CreateSubMenu() As CommandBar Const pop_up_name = "pop-up menu" Dim the_command_bar As CommandBar Dim the_command_bar_control As

我正在尝试创建弹出菜单,它将提供从名为“元素”(椭圆形+文本框)的形状组复制粘贴形状对象的选项。 但似乎选择粘贴方法不起作用

Public Element_Menu As CommandBar

Function CreateSubMenu() As CommandBar

    Const pop_up_name = "pop-up menu"

    Dim the_command_bar As CommandBar
    Dim the_command_bar_control As CommandBarControl

    For Each menu_item In CommandBars
        If menu_item.Name = pop_up_name Then
            CommandBars(pop_up_name).Delete
        End If
    Next

    Set the_command_bar = CommandBars.Add(Name:=pop_up_name, Position:=msoBarPopup, MenuBar:=False, Temporary:=False)

    Set the_command_bar_control = the_command_bar.Controls.Add
    the_command_bar_control.Caption = "Add &Element"
    the_command_bar_control.OnAction = "AddElement"

    Set CreateSubMenu = the_command_bar

End Function

Sub ElementClick()

    Set Element_Menu = CreateSubMenu
    Element_Menu.ShowPopup

End Sub

Sub AddElement()

    ActiveSheet.Shapes("Element").Select 'Selecting template object to replicate
    ActiveSheet.Paste 'Inserting copy out from the clipboard 

End Sub

添加的形状是否正确命名为“元素”(根据不起作用的线条?)似乎它被称为“测试元素”。

好的观点。此外,不要硬编码名称,而是使用
nam
变量。我更改了有关该问题的信息。请参阅初始消息。子例程AddElement()中没有任何参数的相同结果。抱歉,没有参数(正如上面消息中现在所示)宏正在工作!