Word 2010 Macro recorder not capturing shapes

Dreamdweller

New Member
Joined
Apr 20, 2012
Messages
12
I've recorded macros many times but for some reason when trying to record one for inserting a rectangle nothing gets recorded. I'm not sure if I'm supposed to set the document a certain way before I start. But I simply start recording the macro, go to insert find rectangle, draw it to the size I want then hit stop recording. When I open the macro there is no code there at all. I've even tried recording other things like simple text. It records the text just fine but completely ignored the insertion of the shape. Any help? What am I missing?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You probably aren't doing any wrong. When Microsoft updates VBA, they don't always get the macro recorder updated to record everything...
Also, the Word macro recorder doesn't capture all mouse movements. Notice that you can't select anything with the mouse while recording (usually - see a trick below).

That doesn't mean the objects aren't in the model.

Sometimes you can trick Word a little. For example, I used the Select Objects mode (you have to manually add that to the QAT) to select a rectangle I had already drawn on the sheet. THAT got recorded

Code:
ActiveDocument.Shapes.Range(Array("Rectangle 1")).Select

So you can use something like that as a starting point to find the properties and methods available.
 
Upvote 0
The macro recorder is as dumb as a box or rocks and there are many things you can do through the GUI it simply won't capture - especially things that involve the mouse. In this case, as in many others, you simply have to know how to do it yourself. For example, the following macro will insert a 1" square, positioned 1" below and to the right of the start of the paragraph in which the insertion point is located:
Code:
Sub Demo()
ActiveDocument.Shapes.AddShape Type:=msoShapeRectangle, _
  Left:=72, Top:=72, Width:=72, Height:=72, _
  Anchor:=Selection.Paragraphs.First.Range
End Sub
The '72' values in the code are points: 72points = 1". You could use the InchesToPoints or CentimetersToPoints functions instead, if you prefer (e.g. InchesToPoints(1)).
 
Upvote 0
The macro recorder is as dumb as a box or rocks and there are many things you can do through the GUI it simply won't capture - especially things that involve the mouse. In this case, as in many others, you simply have to know how to do it yourself. For example, the following macro will insert a 1" square, positioned 1" below and to the right of the start of the paragraph in which the insertion point is located:
Code:
Sub Demo()
ActiveDocument.Shapes.AddShape Type:=msoShapeRectangle, _
  Left:=72, Top:=72, Width:=72, Height:=72, _
  Anchor:=Selection.Paragraphs.First.Range
End Sub
The '72' values in the code are points: 72points = 1". You could use the InchesToPoints or CentimetersToPoints functions instead, if you prefer (e.g. InchesToPoints(1)).

I've found that the recorder seems to record the insertion of the rectangle if I save it as a .DOC instead of a .DOCX file. Not sure why it works for one and not the other. But as you said there are issues with the recorder not being all that great.
 
Upvote 0
object model between versions (classic and 07/10/13) changed a lot... don't know if your classic code will run properly in a newer version.
It is interesting that it uses the document version to classify it.
 
Upvote 0
object model between versions (classic and 07/10/13) changed a lot... don't know if your classic code will run properly in a newer version.
It is interesting that it uses the document version to classify it.
The document version makes no difference to whether the code will run - the demo I posted was created on Word 2010 but works equally well on all earlier versions. The only difference the version makes in this case is as to whether the macro recorder will record the process.
 
Upvote 0

Forum statistics

Threads
1,225,665
Messages
6,186,312
Members
453,349
Latest member
neam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top