Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a Word document via vba?

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
We have a couple hundred word documents that need to be converted to pdfs. However, the pdf convertor is confused and the conversion is done incorrectly. The reason for the confusion is the way these word documents were created. The word documents contain a header and a footer. The header and footer each contain multiple images, one on top of the other (bascially the same image duplicated several times). The main document contains an image that covers the other the images in the header and footer. (I have no idea why any of this was done this way.)

So, is it possible to programmatically loop thru all the word documents, open each one individually, search for the images within the document and delete them? If so, how?
 
I can tell you it's very likely possible, but I don't have any code to show you. But like all the Office applications, Word can be controlled with OLE automation. It would start with something like:

Dim objWord As Word.Application
Set objWord = New Word.Application

From there, you would be opening Word documents, navigating through the object hierarchy to the header and footer sections, and there would probably be some kind of Images or Pictures collection that you could delete items from.


 
It can't find Word.Application. What Reference do I need to set?
 
What Reference do I need to set
Microsoft Word x.0 Object Library

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That's what I thought. But I get an error that says the name conflicts with existing module, project, or object library.

I deleted all references except for:
Visual Basic for Applications
Microsoft Access 11.0 Object Library

So what am I missing?
 
At one stage I needed to go through word textboxes and update the image. I found SkipVought's post helpful:
Replace not working in VBA - Word 2000
thread68-794360.

I wonder would it be better for you to do this from a Word module?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top