Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2015, 08:29 AM
tunes10590 tunes10590 is offline Assign Macro to Shape in Word 2013 Windows 7 64bit Assign Macro to Shape in Word 2013 Office 2013
Novice
Assign Macro to Shape in Word 2013
 
Join Date: Jan 2015
Posts: 4
tunes10590 is on a distinguished road
Question 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
Reply With Quote
  #2  
Old 01-26-2015, 04:53 PM
Guessed's Avatar
Guessed Guessed is offline Assign Macro to Shape in Word 2013 Windows 7 32bit Assign Macro to Shape in Word 2013 Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,630
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
Default

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?
Reply With Quote
  #3  
Old 01-27-2015, 06:08 AM
tunes10590 tunes10590 is offline Assign Macro to Shape in Word 2013 Windows 7 64bit Assign Macro to Shape in Word 2013 Office 2013
Novice
Assign Macro to Shape in Word 2013
 
Join Date: Jan 2015
Posts: 4
tunes10590 is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 01-27-2015, 06:40 AM
gmayor's Avatar
gmayor gmayor is offline Assign Macro to Shape in Word 2013 Windows 7 64bit Assign Macro to Shape in Word 2013 Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 3,570
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

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
Reply With Quote
  #5  
Old 01-27-2015, 05:38 PM
Guessed's Avatar
Guessed Guessed is offline Assign Macro to Shape in Word 2013 Windows 7 32bit Assign Macro to Shape in Word 2013 Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,630
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
Default

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
Reply With Quote
  #6  
Old 01-27-2015, 05:51 PM
macropod's Avatar
macropod macropod is offline Assign Macro to Shape in Word 2013 Windows 7 64bit Assign Macro to Shape in Word 2013 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,224
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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]
Reply With Quote
  #7  
Old 01-28-2015, 08:25 AM
tunes10590 tunes10590 is offline Assign Macro to Shape in Word 2013 Windows 7 64bit Assign Macro to Shape in Word 2013 Office 2013
Novice
Assign Macro to Shape in Word 2013
 
Join Date: Jan 2015
Posts: 4
tunes10590 is on a distinguished road
Default

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?
Reply With Quote
  #8  
Old 01-28-2015, 04:41 PM
macropod's Avatar
macropod macropod is offline Assign Macro to Shape in Word 2013 Windows 7 64bit Assign Macro to Shape in Word 2013 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,224
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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
and assumes your picture content control's Title = "MyPic". The code would be added to the document's 'ThisDocument' code module. The above is a trivial demo that just changes the image's width back & forth from 1 to 4 cm.

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]
Reply With Quote
  #9  
Old 01-29-2015, 06:26 AM
tunes10590 tunes10590 is offline Assign Macro to Shape in Word 2013 Windows 7 64bit Assign Macro to Shape in Word 2013 Office 2013
Novice
Assign Macro to Shape in Word 2013
 
Join Date: Jan 2015
Posts: 4
tunes10590 is on a distinguished road
Default

Thank you all for your assistance.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign Macro to Shape in Word 2013 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 to Shape in Word 2013 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:00 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft