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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch image change in Word/Excel Docs. 3

Status
Not open for further replies.

gregmosu

Programmer
Jul 8, 2002
117
US
Does anyone have any information on how to change an image in numerous Word and Excel documents w/a batch process instead of individually changing the image in every document?

Thanks,
Greg
 
Skip,

I've got family in Houston. Does the heat bother you? :)

-Greg
 

Greg,

It's a tradeoff.

2 months of winter & 4 months of summer vs the inverse. It actually bothers more now, at 63, than it did 10 years ago.

The first summer we were in Texas, we had one of the longest spells of over 100oF. I officiated at many Little League games in that kind of heat over a 20 year period.

Skip,

[glasses] [red]Be advised:[/red]To be safe on the FOURTH, don't take a FIFTH on the THIRD, or...
You might not come FORTH on the FIFTH! [bomb][tongue]
 
My brother went down for a visit last summer, and said it was miserable. They never left the house... and when they went to the store, he said his shoes were acutally melting to the blacktop.
 
Well, or is that waaall? (as in a drawl....doh!), I lived in India and Pakistan for two years. Try 140 degrees...in the shade!

Here in the lovely Pacific NorthWest in never gets that hot. At least on on the coast. Inland, yup it does.

Anyway....but to the issue at hand.

OK, so now you making an executable that you want to run from a commandline. Not sure why you are going this route, but OK, sure.

If the code has a problem with wdGoToGraphic, then there is either a version problem - uh, what version are you dealing with?; OR there is a reference problem. That is why I asked if anyone knows if this "New Microsoft.Office.Interop.Word.ApplicationClass"
has all the full references that "New Word.Application" would have.

Gerry
 
Fumei, sorry for the misunderstanding. I thought the code you gave me was supposed to go in a console app. or something like that. Is what you gave me supposed to go in a macro? I'm totally confused as to where the code is supposed to go. I'm using Office Word 2003... not sure what version of VB that uses, 6 or earlier..?

-Greg
 
I haven't tested this - I got totally confused with all these Texan drawls.

Am I correct in thinking that a VB.Net Console Application solution is required?

If so:

Code:
Module Module1

  Sub Main()

    Dim oFile As String
    oFile = Dir("c:\temp\*.doc")
    Do While oFile <> ""
      Dim WordApp As New Word.ApplicationClass
      Dim zzz As Word.WdGoToItem = Word.WdGoToItem.wdGoToGraphic
      WordApp.Documents.Open(FileName:="c:\temp\" & oFile)
      With WordApp.Selection
        .GoTo(Word.WdGoToItem.wdGoToGraphic, Count:=1)
        .Delete()
        .InlineShapes.AddPicture(FileName:="C:\temp\2.jpg")
      End With
      If WordApp.ActiveDocument.Saved = False Then WordApp.ActiveDocument.Save()
      WordApp.ActiveDocument.Close()
      oFile = Dir()
    Loop


  End Sub

End Module

Don't forget I've not tested it - its basically gregmosu's last piece of code modified until the blue wavy lines disappeared [smile]

To use it:

Start a new Console Application project in VS.NET.

You should see:

Module Module1
Sub Main
End Sub
End Module

replace that with my code - you will see some lovely blue wavy lines.

In Solution Explorer (on the right hand side of the screen), right click on References and select Add Reference ..., when the dialog box appears, switch to the COM tab and find Microsoft Word X.0 Object Library (X = your version number), hightlight it, click Select and then click OK - lo and behold the wavy lines should disappear.

From the main menu select Build | Rebuild Solution. That will create a .EXE in the BIN sub folder of you Solution's folder.

Now your on your own!!
 
Delete the line:

Dim zzz As Word.WdGoToItem = Word.WdGoToItem.wdGoToGraphic

that was just me trying to find the correct syntax to use wdGoToGraphic

sorry about that.
 
Earthandfire, that worked perfectly! Thanks for your help! I can do pretty much the same for spreadsheets by using the Excel component right?

Thanks again,
Greg
 
Not without a small change - check Skip's code for how to refer to the Workbook and Worksheets, but in principle yes.

Glad we got it sorted at last.
 
Yeah, you guys are great! I'd have been lost w/out you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top