# Word 2010 Macro recorder not capturing shapes



## Dreamdweller (Feb 14, 2014)

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?


----------



## starl (Feb 14, 2014)

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


```
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.


----------



## Macropod (Feb 14, 2014)

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:

```
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)).


----------



## Dreamdweller (Feb 15, 2014)

Macropod said:


> 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:
> 
> ```
> Sub Demo()
> ...



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.


----------



## starl (Feb 15, 2014)

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.


----------



## Macropod (Feb 15, 2014)

starl said:


> 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.


----------

