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

时间:2014-02-25 03:05:30

标签: excel vba popup commandbar

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

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

1 个答案:

答案 0 :(得分:1)

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