How to dynamically insert text into a word document.
Hello,
I have a button in a word document. If I click on the button, I would like to add a carriage return after it and then write some text. How to do that ?
Thank you in advance for your help,
mathmax
[265 byte] By [
mathmax] at [2008-3-1]
You don't give us enough information.
What version of Word?
What kind of button? (If you're unsure, tell us how you created and placed it on the document)
Which programming language?
In basic terms, you need to determine the range where the button is, then use the InsertAfter methods. But in order to tell you how to get that range, we need the above information.
mathmax wrote: |
| What version of Word? Word 2007 What kind of button? (If you're unsure, tell us how you created and placed it on the document) Just a Button control I've dragged and dropped from the toolbox to my word document. But does the way to process depends on the type of button ? Which programming language? c# 3.0. I use VST0 3.0 from VS 2008 beta 2. | |
In that case, I'm going to move this post to the Orcas forum. I'm guessing that the button in VSTO 2008 is the same as in 2005. In that case, it would have been inserted as an InlineShape. This means you can select it and insert a bookmark around it. Then use the bookmark's range. Like this, although no guarantees that it will work exactly the same in 2008
object objBkmName = "bkmButton";
Word.Bookmark bkm = this.Bookmarks.get_Item(ref objBkmName);
Word.Range rng = bkm.Range;
rng.InsertAfter("\rsome text");
Edit: Oh, and there are at least three different kinds of buttons that can be used on Word documents, which is why I asked for clarification :-)
"bkmButton" is the name of the button, isnt'it ?
I get an execution error on the second line : "The required member of the collection doesn't exist" (translation). What does that mean ?