Welcome to the Q&A Community
I’m here to assist your problem.
Base on your description, I recommended you:
1/ Enable Developer tab (if not already visible):
- Go to File > Options > Customize Ribbon.
- In the right pane, check the box for Developer.
- Click OK.
2/ Insert a picture content control:
*Open your .docm document.
*Place your cursor where you want the clickable image:
- Go to the Developer tab > Controls group.
- Click the Picture Content Control button (it looks like a small picture frame icon).
- This inserts a placeholder control. Click inside it to browse and insert your desired image (e.g., your icon). The image will fill the control
3/ Configure the content control properties:
- Select the picture content control (click on it).
- In the Developer tab > Controls group, click Properties.
- In the dialog box:
- Set the Title to a unique name, such as "RunMySub" (this will be used in the VBA code to identify it).
- Optionally, check Content control cannot be deleted and Contents cannot be edited to prevent accidental changes.
- Click OK.
4/ Add the VBA Event handler:
- Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
- In the Project Explorer pane (on the left), expand your document (e.g., "ThisDocument" under the document name).
- Double-click ThisDocument to open its code module.
- Paste the following code into the module:
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
If ContentControl.Title = "RunMySub" Then
' Call your existing subroutine here
Call YourSubroutineName
End If
End Sub
- Replace "RunMySub" with the title you set in Step 3.
- Replace YourSubroutineName with the actual name of your VBA subroutine (e.g., MyMacro).
- If your subroutine has parameters, include them in the Call statement as needed.
- Save the changes (ensure the document is saved as .docm to preserve macros).
5/ Test and Check:
- Return to the Word document.
- Click the image in the Content Control.
- The macro should execute immediately.
- Note: If the document has multiple controls, ensure titles are unique to avoid conflicts. Tabbing into the control will also trigger it, but for image-based "buttons," clicking is the primary interaction.
We appreciate your kind patience and understanding that sometimes the initial response may not immediately resolve the issue or there may be some misunderstandings about your scenario, but we would love to hear updates from you and find out further suggestions.
Thank you for your kindness and understanding. If you need anything else, please feel free to contact me.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment"
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.