Replacing text with AutoText entries in Word 2007 using VB.NET

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello everyone,
i have a question in regards Word 2007 and VB.Net.
Im trying to replace a specific text in a word document, that might exist in 4-5 places in the document, using VB.net. These texts will be inside a table 1 row long with 3 columns. That table might be repeated more that 1 time in each page.
In theory i should be able to find the text in question (e.g. strLogo) and replace it with the AutoText Entry with the same name (strLogo).
the code that im using is the following:

Dim rng As Word.Range
oWord.NormalTemplate.BuildingBlockEntries.Item("strLogo").Insert(rng)
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small




This code will actually erase the text from the whole document and add the Autotext as the only thing in the word document.
The pseudo code would be like this:

for all the word document
find "strLogo"
insert "strLogo".Autotext.Entry
end find
end for

Is there a way to do that? I have tried everything but nothing seems to work. Any help will be much appriciated. Thank you in advance.

View the full article
 
Back
Top