Question

I want to add a button to a textbox in a word document. The button should stick to the textbox like this:

----------------------------------------
word document content
text, text, a textbox follows

------------------[button1]-
|text box content          |
----------------------------

text, followed by another textbox

------------------[button1]-
|textbox2 content          |
----------------------------

more text

---------------------------------------

I have been able to add a button using vba, but I don't know how to make it stick to the textbox since I can have more instances to textboxes with buttons.

I would like to do this using macros, but a C# addin solution is also welcomed.

Was it helpful?

Solution

I'm afraid it isn't possible to overlay a button to a textbox like you show, and make them stick together. To overlay them, you need to set their layout wrapping style to something else than "in line with text" (e.g. "Square") but then Word won't let you group them (at least not my Word 2003) so in principle they can be moved relative to each other.

However if you create a button and a text box next to each other and leave the wrapping style be "in line with text" which is the default, then they will stay side by side and not move relative to each other (unless you type text in between them).

Selection.InlineShapes.AddOLEControl ClassType:="Forms.CommandButton.1"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.InlineShapes.AddOLEControl ClassType:="Forms.TextBox.1"

Then you can your other textbox-button pairs on the following lines.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top