1

I wanted to count all the shapes in certain word document using word macros using this code

Set objWord = GetObject(, "Word.Application")
objWord.Visible = True

Set objDoc = objWord.Documents.Open("D:\Test.docx")
Set var1 = objWord.ActiveDocument
Set var2 = var1.Shapes
Set var3 = var2.Count

but I get this error when executing the script

"at line 7 - Error: Object required: var2.Count"

What is wrong with this ?

becks
  • 2,656
  • 8
  • 35
  • 64
  • 1
    .Count is a simple variable, not an object - so drop the `Set` before `var3`. See http://stackoverflow.com/a/15053412/603855 – Ekkehard.Horner Feb 25 '13 at 14:45
  • See [What does the keyword Set actually do in VBA?](http://stackoverflow.com/questions/349613/what-does-the-keyword-set-actually-do-in-vba) – Tomalak Feb 25 '13 at 14:47
  • when I removed Set keyword, I get an error which is "Count is not a method" My question is how to show this count in a message box or in command line ? – becks Feb 25 '13 at 14:52
  • 1
    Try `WScript.Echo objWord.ActiveDocument.Shapes.Count`. – Ansgar Wiechers Feb 25 '13 at 16:51

0 Answers0