Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Excel Macro for Word field code (MS Word 2003 (SP3))

    Link to post added by HansV - see <!help=19>Help 19<!/help>

    Hello,

    First, I am not sure if this belongs in the Excel forum or the Word forum, since this will use both Excel and Word.

    Ok, I have a folder full of word documents and every graphic or drawing is linked to file.

    I also have a spreadsheet with the following rows:

    D ROW - contains all the OLD graphic file names
    E ROW - contains the NEW (proposed) graphic file names

    I would like to have an MS Excel macro that will point to a folder full of MS Word .DOC files and:

    1. Look at each and every MS Word .DOC INCLUDEPICTURE field code and replace the original name with the new name.

    In other words, the macro will look at the old graphic name (cell D5), and then look at the new graphic name (E5)
    and then insert the new name into that space in the INCLUDEPICTURE field code.

    The designated folder on the computer drive already contains the new catalog name (e.g. a00100.ai). I just need that
    new name inserted into the segment of each INCLUDEPICTURE field code.

    I have have attached a screen shot to better illustrate the process I am trying to make happen.

    Any assistance that can be provided, is very much appreciated..

    One last thing, I may be able to re-use some of the code that came out of the question - based on post number: <post:=715,719>post 715,719</post:>

    Here is that code:

    Sub RenameFiles()
    ' Modify as needed but keep trailing backslash
    Const strPath = "C:Pictures"
    Dim r As Long
    Dim n As Long
    n = Cells(Rows.Count, 4).End(xlUp).Row
    For r = 5 To n
    Name strPath & Cells(r, 4) As strPath & Cells(r, 5)
    Next r
    End Sub

    Thanks in advance for any suggestions.

    Regards,

    Jim
    Attached Images Attached Images

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel Macro for Word field code (MS Word 2003 (SP3))

    You should be able to do this yourself by combining the many code examples you've already received for replacing text in field codes for all documents in a folder with the macro in your post.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Excel Macro for Word field code (MS Word 2003 (SP3))

    Hello Hans,

    So, I hear what you are saying, but I have one question.

    Does it matter or not, that I would be trying to manipulate the INCLUDEPICTURE field code in MS Word from a macro in MS Excel?


    Thanks,

    Jim

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel Macro for Word field code (MS Word 2003 (SP3))

    You'd be using Automation, i.e. you'd start Word from Excel and manipulate the documents using Word VBA from Excel.

    See WendellB's tutorial Automation 101; it contains an introduction and useful links.

    If you search for word.application excel in this forum and in the Excel and VB / VBA forums, you'll find many examples of running Word code from Excel.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Excel Macro for Word field code (MS Word 2003 (SP3))

    Hello everyone,

    I have a spreadsheet that I have put together that is composed of two columns (Column D and Column E).

    From this Excel spreadsheet (macro), I would like the macro to:


    1. Point to a folder full of MS Word 2003 .DOC files and open each document.
    2. Find old graphics fieldcode path in D4 cell.
    3. Rename fieldcode path in word document to new path, based on graphics catalog number (or desired fieldcode path) found in E4.
    4. Repeat the process for D5/E5 and so on...

    For example:

    --------------------------------------------
    EXAMPLE 1:

    EXCEL SPREADSHEET:

    D4 CELL (legacy fieldcode path)

    GraphicsCatalogRouter.jpg

    E4 CELL (new graphics catalog number)

    G00100.jpg

    WORD DOCUMENT FIELDCODE (desired end result):

    GraphicsCatalogG00100.jpg
    --------------------------------------------
    EXAMPLE 2:

    EXCEL SPREADSHEET

    D4 CELL (legacy fieldcode path)

    GraphicsCatalogRouter.jpg

    E4 CELL (new graphics fieldcode path)

    GraphicsCatalogG00100.jpg

    WORD DOCUMENT FIELDCODE (desired end result):

    GraphicsCatalogG00100.jpg
    --------------------------------------------------


    Hans, I appreciate all the interesting information on how to work Word files from Excel, but right now, I need to find
    whatever code I can find in the forums and get this macro working asap.

    With that said, ANY help you (or anyone else) can provide is very much appreciated.

    Thanks to all for any assistance rendered.

    Regards,

    -J

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel Macro for Word field code (MS Word 2003 (SP3))

    See if you can use the attached code as starting point. It's air code, I haven't tested it.

    PS Woody's Lounge cannot provide solutions "ASAP". We do our best, but we're all volunteers.
    Attached Files Attached Files

  7. #7
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Excel Macro for Word field code (MS Word 2003 (SP3))

    Hello Hans,

    Thanks for the quick response. I will give the macro a try and see what happens.
    Yes, I understand your other comment. I totally understand the good natured volunteer effort that goes into this forum - just a little frustration on my end. Anyway, I appreciate all you have done.
    Thanks,
    Jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •