#1
|
|||
|
|||
Assign Macro to Shape in Word 2013
Hello All, Is there way to assign a macro to a shape or picture in Word 2013 as you can in Excel? If there is not an easy way, would it be possible to do something with VBA? I thought I could use something like Private Sub CommandButton21_Click() but use the name of the shape in place of the name of the command button, but I can'e even find a place to get the properties box for the shape to get the shape name. Thank you, Amber |
#2
|
||||
|
||||
What exactly are you trying to do?
Are you trying to use VBA to create a macro that runs when someone clicks on an existing shape or do you want to add a shape to a document by running a macro? |
#3
|
|||
|
|||
Hello and thanks. I have a VBA macro currently setup and assigned to a control command button. But I need it to be more visible and not easily missed. What I usually do in Excel, is make a big red rectangle and assign a macro to that. So the person presses the big red rectangle and the macro runs. But that does not seem to be an option in Word.
|
#4
|
||||
|
||||
Insert a button, make it as large as you like and set its background colour property to red.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
||||
|
||||
The way to do this in Word is to insert a macrobutton field. This allows you to place text on the page which can be doubleclicked to run a macro. You can style the text as large as you like (as long as it fits on a single line) and even add a background shading. It is not the same as Excel but it is a reasonable facsimile
An example of the field code to run at macro by double clicking is {macrobutton MacroName DoubleClick to run the MacroName macro} Note that the curly brackets are inserted by pressing Ctrl-F9 |
#6
|
||||
|
||||
If you use a picture content control, you can add whatever size picture (e.g. 'a big red rectangle') you want to that and have a Document_ContentControlOnEntry macro run whatever process you want as soon as the picture is clicked on. MacroButton fields containing pictures don't execute their macros when clicked on in Word 2007 & later.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Thanks for all your feedback
@ gmayor - Thank you. I had totally forgotten that you could activate the palette in the properties box. That will fix my problem for now. However, I would like to learn to better use controls in Word. Honestly, I find certain things in Word so difficult to work with, that I often design things in Excel or Access, and avoid using Word for anything complex. @ Guessed - I am not sure that I understand what you mean by inserting a macrobutton field. Is that in VBA or the document itself? Can you point me to a video or tutorial that discusses this? @ macropod - Again, sorry but I am not familiar with the Document_ContentControlOnEntry process. I Googled a little, but didn't find anything that explained the process in a way I could understand. Can you point me anywhere? Thanks to all for your help. Just as a side note, does anyone know why Word makes assigning and using macros so much harder than Excel. In Excel, pretty much anything you insert (picture, most controls, text boxes, etc) all you have to do is right click and assign macro. The control button even prompts you to assign a macro when you drop it in. Wonder why Word is so much more complicated? |
#8
|
||||
|
||||
A Document_ContentControlOnEntry macro might be coded as:
Code:
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl) With ContentControl If .Title = "MyPic" Then With .Range.InlineShapes(1) If .Width > CentimetersToPoints(1) Then .Width = CentimetersToPoints(1) Else .Width = CentimetersToPoints(4) End If End With End If End With End Sub I don't agree that "Word makes assigning and using macros so much harder than Excel". It's not harder, just different in some respects.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Thank you all for your assistance.
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to assign a key shortcut to a particular shape in word? | Retko | Word | 5 | 08-23-2014 09:04 PM |
Assign keyboard short cut to macro | AndyDDUK | PowerPoint | 1 | 01-09-2013 09:28 AM |
Assign macro but hide the button/field | trlear | Word VBA | 5 | 02-23-2012 04:35 PM |
Run Macro & Activate shape | ibrahimaa | Excel Programming | 1 | 01-21-2012 02:14 AM |
How do I assign a macro to a button when the macro is in my personal workbook? | foolios | Excel Programming | 2 | 07-27-2011 02:41 PM |