Steve G.
Steve G.

Reputation: 409

MS Word Ignores Content Control Inside a Rich Text Box

Is there a reason why my MS Word VBA macro is ignoring a dropdown list I placed inside a shape (a rich text box)? I've tried referring to it by tag, name, number, etc. I even had the macro tell me the count of content controls:

MsgBox(ActiveDocument.ContentControls.Count)

I get 0.

Nothing works. If I take it out of the shape, it works fine. MS Word gives me a count of 1 item. But for some reason MS Word won't acknowledge it inside the shape. Any help on how to do this?

Upvotes: 0

Views: 1035

Answers (1)

user1379931
user1379931

Reputation:

Edited as my previous post was completely wrong.

Each textbox in the main text story is a Shape which you can access using an index number. A shape has various properties but text etc. is in its Textframe, if it has one. But in that case the Range you need is not called Range but TextRange. So, e.g. the first contentControl in Shape 2 is

ActiveDocument.Shapes(2).TextFrame.TextRange.ContentControls(1)

You will probably need to iterate through your shapes and you may need to verify that a given shape is a textbox and/or that it has a TextFrame.

If your text box is in another Story such as a header or footer, you will probably need to identify the relevant StoryRange.

Upvotes: 2

Related Questions