Consulting

Results 1 to 4 of 4

Thread: vba Word: How to add selected text into right click menu, or add right clicked word i

  1. #1

    Red face vba Word: How to add selected text into right click menu, or add right clicked word i

    I want to add Selected text into right click menu as a .caption
    here is my code

    
    
    PublicSub CreateMacro()
    Application.CommandBars("Text").Reset
    
        Dim MenuButton As CommandBarButton
        With CommandBars("Text")
            Set MenuButton =.Controls.Add(msoControlButton)
            
            
            With MenuButton
                .Caption = Selection.Text
                
                
                
                
                .Style = msoButtonCaption
                .OnAction ="Test_Macro"
            EndWith
        EndWith
    
        
    EndSub
    
    PublicSub Test_Macro()
        MsgBox "I work"
        ResetRightClick
        CreateMacro
    EndSub
    
    Sub ResetRightClick()
        
        Application.CommandBars("Text").Reset
             
    EndSub
    
    
    
    







    on first attempt right click menu is displayed but empty caption, and on next times it show older caption (not current selection) until the menu item is clicked
    or how to add Right clicked word into right clicked menu




  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted at: http://www.msofficeforums.com/word-v...text-into.html
    Please read VBA Express' policy on Cross-Posting in item 3 of the rules: http://www.vbaexpress.com/forum/faq...._new_faq_item3
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

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