• VBA – Word2K, Change source on linked picture (Env: W2K, O2K both Pro, UK

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » VBA – Word2K, Change source on linked picture (Env: W2K, O2K both Pro, UK

    Author
    Topic
    #388620

    Hi,

    In multiple documents, I have a large number of linked pictures that I need to automatically change paths on (approx. 70 in each file).

    In Word, I would normally for a few number of pictures manually use “Edit/links/change source”
    But in VBA for “fields” and “linkformat”, I cannot find a “change source” method.

    How can I then change the paths for these files ??

    Thanks,
    ;O)) Henrik

    Viewing 0 reply threads
    Author
    Replies
    • #683131

      Take a look at macropod’s Star Post post 261488

      • #684210

        Thanks Hans,

        ….but finding heads and tales of that discussion is a bit confusing – not being a part of it…

        Meanwhile I received a really useful tip from a Word MVP

        ‘By Doug Robbins – to update links in a document
        Dim alink As Field, linktype As Range, linkfile As Range
        Dim linklocation As Range, i As Integer, j As Integer, linkcode As Range
        Dim Message, Title, Default, Newfile
        Dim counter As Integer

        counter = 0
        For Each alink In ActiveDocument.Fields
        If alink.Type = wdFieldLink Then
        Set linkcode = alink.Code
        i = InStr(linkcode, Chr(34))
        Set linktype = alink.Code
        linktype.End = linktype.Start + i
        j = InStr(Mid(linkcode, i + 1), Chr(34))
        Set linklocation = alink.Code
        linklocation.Start = linklocation.Start + i + j – 1
        If counter = 0 Then
        Set linkfile = alink.Code
        linkfile.End = linkfile.Start + i + j – 1
        linkfile.Start = linkfile.Start + i
        Message = “Enter the modified path and filename following this
        Format ” & linkfile
        Title = “Update Link”
        Default = linkfile
        Newfile = InputBox(Message, Title, Default)
        End If
        linkcode.Text = linktype & Newfile & linklocation
        counter = counter + 1
        End If
        Next alink

        Bests,
        Henrik

        • #684256

          I’m glad that you found a solution. I notice that you have to specify a path and file name for each link field in the document individually. If that suits your purpose, fine. It gets cumbersome, though, if you only moved the files from one folder to a different folder. Macropod’s macro in the attachment to post 261488 lets you specify a path once, then substitutes this in all link fields.

        • #684446

          Hi Henrik,

          Re:[indent]


          ….but finding heads and tales of that discussion is a bit confusing – not being a part of it…


          [/indent] I’ve now added a synopsis to help make things clearer. With a task the size of your’s, I think I’d prefer not to be asked for every source file’s name and path – though my solution doesn’t deal with source files that are in multiple folders.

          Cheers

          Cheers,
          Paul Edstein
          [Fmr MS MVP - Word]

          • #684469

            Hi M-pod

            Thanks for the synopsis.

            You’re absolutely right, about this getting tedious.
            My problem is that it’s a many-to-many (some 20 folders and approx. 140 files)
            (I’ve done a select case to map folders appropiately)

            What I forgot to mention in my answer to your discussion was that specifically the messagebox bit I had taken out and modified the code accordingly.

            My mistake, apologies.

            Bests,
            Henrik

            PS: Any idea or news as to when the disabled search function becomes available again (I’m taking that it will be….??)

            • #684482

              >> PS: Any idea or news as to when the disabled search function becomes available again (I’m taking that it will be….??)

              Unfortunately, we don’t know. claude (Claude) has to do everything in his spare time, and he hardly has any the moment. If there are new developments, they will be announced in the Newsflash.

            • #687377

              Hi there Henrik,

              You might want to check out the updated post http://windowssecrets.com/forums/showthread//154379-Word-Fields-and-Relative-Paths-to-External-Files – the new version of the field link updater provides much more flexibility and caters for the many-to-many relationships you’re working with.

              Cheers

              Cheers,
              Paul Edstein
              [Fmr MS MVP - Word]

    Viewing 0 reply threads
    Reply To: VBA – Word2K, Change source on linked picture (Env: W2K, O2K both Pro, UK

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: