Shawn V. Wilson
Shawn V. Wilson

Reputation: 1111

Word VBA: Make macro easy to run

I've made a form-letter document with a macro that performs the mail merge. I don't want the user to have run it from the menus, and I want this to be portable. If there's a way for a button to appear on each user's ribbon or quick command menu, I'm not familiar with it.

So I put a button in the document itself. Unfortunately, every form-letter created has the same button in it. I suppose I could write the code to delete every one, but I think that would be slow.

Is there a way to assign a shortcut key to an existing macro, and have it reside in the document?

Upvotes: 1

Views: 83

Answers (1)

James SMith
James SMith

Reputation: 83

I had to implement something pretty similar to what you were referring to some 10 staff. My solution (by no means as portable as desired) was to export the macros and forms from my Normal template to the other users, I coupled this with Ribbon customization and it worked well. Unfortunately, when a change was needed, I had to trudge over to everyone's machine individually.

I would suggest you stick with your solution of deleting button after the merge is complete. Here's some code to help with that:

Sub DeleteCommandButton()
    For Each o In ActiveDocument.InlineShapes
        If o.OLEFormat.Object.Name = "CommandButton1" Then
            o.Delete
        End If
    Next 
End Sub

Good luck, hopefully this helps.

Upvotes: 2

Related Questions