Replacing words in a Microsoft Word Document.

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
aquawicket
Earned some good credits
Earned some good credits
Posts: 103
Joined: Sun Aug 05, 2007 5:49 am

Replacing words in a Microsoft Word Document.

Post by aquawicket » Sun May 31, 2009 10:20 pm

I would like to replace words, or more so {variables} in a Microsoft word documents. I've got as far as to open the document VIA OLE.

Code: Select all

wxAutomationObject wordObject;
wxString docPath = "C:\\original.doc"; 
wordObject.CreateInstance(wxT("Word.Application"));
wordObject.PutProperty("Visible","1");
wordObject.CallMethod("Documents.Open",docPath);
Now I want to find all of the words in the document enclosed in {}. For example.

{FirstName}
{LastName}
{Email}

And then replace them. I looked around in OLE code of MS word but didn't find much on how to do this. I also wanna stay away from using special Merge and Bookmark stuff in word. I want people to simply be able to put {varibles} in their doc and be done with it. Any pointers in the right direction would be appreciated.

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Mon Jun 01, 2009 5:26 pm

Maybe have a look at this link. It doesn't use variables, but I think it does what you want.

http://www.fontstuff.com/vba/vbatut09a.htm

Post Reply