1. #1
    Time's Avatar
    Registered
    14/04/03
    Location
    Gent
    Posts
    26,761
    iTrader
    7 (100%)
    Mentioned
    0 Post(s)
    Reputation
    0/200

    Macro werkt niet via contextmenu

    Ik ben wat aan het prutsen met een kleine macro en wou die toevoegen aan het rechtklikmenu in excel. Probleem is nu dat de macro waar het allemaal om draait wel werkt als ik hem uitvoer via beeld/macro's weergeven/uitvoeren, maar niet als ik hem selecteer via het contextmenu bij rechtklik. Terwijl die exact diezelfde macro aanroept. Ziet iemand wat ik hier verkeerd doe?

    De bedoeling is dat je een selectie van cellen maakt en de macro kopieert en onmiddelijk terug waardes plakt. Heeft het iets te maken met dat je de actieve selectie anders moet definiƫren als je de macro vanuit het contextmenu oproept?

    Ik vermoed dat ik selection.copy anders moet definiƫren, maar dan begrijp ik helemaal niet waarom de macro wel werkt als ik hem rechtstreeks aanroep.

    Code:
    Const strMacro = "Waardes plakken"
    
    Sub MACRO_ACTIVEREN()
       Dim cBut
       Call KillMacro
       Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True)
       With cBut
           .Caption = strMacro
           .Style = msoButtonCaption
           .OnAction = "plakkenwaardes"
       End With
    End Sub
    
    Sub plakkenwaardes()
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
    End Sub
    
    Sub KillMacro()
       On Error Resume Next
       Application.CommandBars("Cell").Controls(strMacro).Delete
    End Sub
    Bedoeling is normaal dat je MACRO_ACTIVEREN activeert, waarna je in je contextmenu de optie bij krijgt. Als ik die probeer te gebruiken krijg ik de foutmelding dat het niet kan uitgevoerd worden.
    Last edited by Time; 30-12-2013 at 21:00.
    WANN DU DEINE PFERDEKOPF NICHT GESCHLOSSEN HALT GEHEN WIR DU EINEM FACIAL GIEBEN
    no votes  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in