• Batch embed of graphics (Word 2000 SR-1)

    • This topic has 10 replies, 4 voices, and was last updated 22 years ago.
    Author
    Topic
    #388229

    Hi,

    I’m trying to loop through documents that have graphics linked in with the INCLUDEPICTURE link. I want to break those links and embed the graphics in the document. Here’s the code I’m trying:

    Sub EmbedGraphicsProcess()

    Selection.HomeKey Unit:=wdStory

    Do

    Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, count:=1, Name:=”INCLUDEPICTURE”
    Selection.Find.ClearFormatting
    Selection.Find.Execute
    Selection.Fields.Unlink

    Loop While Selection.Find.Found = True

    End Sub

    Problems include:

    — Pictures disappearing when the links are broken.

    — The Found property always testing False, even when an INCLUDEPICTURE link is found

    Thanks,
    Bob

    Viewing 1 reply thread
    Author
    Replies
    • #680716

      Find and GoTo are independent of each other. By setting GoTo to look for INCLUDEPICTURE fields, you don’t set anything for Find, so Find.Found is False. Try the following instead:

      Sub EmbedGraphicsProcess()
      ActiveWindow.View.ShowFieldCodes = True
      Selection.HomeKey Unit:=wdStory
      With Selection.Find
      .ClearFormatting
      .Text = “^dINCLUDEPICTURE”
      .Execute
      Do While .Found
      Selection.Fields.Unlink
      Selection.Collapse wdCollapseEnd
      .Execute
      Loop
      End With
      ActiveWindow.View.ShowFieldCodes = False
      End Sub

      This code temporarily displays field codes, and looks for the field code (^d) for INCLUDEPICTURE.

      • #680732

        Thanks for the quick response. I’m still having trouble, though. With field codes visible, I can Find.Text = “^d” and I can Find.Text = “INCLUDEPICTURE” but I can’t Find.Text = “^dINCLUDEPICTURE”. Also, when I unlink the graphics while the field codes are visible, the graphics disappear.

        Thanks,
        Bob

        • #680735

          Does it work if you try to find ^d INCLUDEPICTURE (with a space between ^d and INCLUDEPICTURE)? It depends on the way the INCLUDEPICTURE fields have been inserted – if there is a space between the left field bracket { and INCLUDEPICTURE, there should be a space in Find.Text too.

          • #680755

            Adding a space after ^d makes a difference. I created a second With loop that looks for “^d INCLUDEPICTURE”and now every graphic is being processed, which is good. I’ll have to work on that graphics issue. The placeholders show, but nothing else shows. I tried printing the doc, and there’s just blank spaces where the graphics should be.

            Thanks for your help,
            Bob

            • #680803

              Hi Bob:
              Do you have Tools/Options/View tab/picture placeholders UNchecked?
              Cheers,

            • #680816

              <<Do you have Tools/Options/View tab/picture placeholders UNchecked?

              Yes, I thought of that earlier and it's unchecked. It's strange–some of the graphics unlink properly and some don't. I've been comparing everything possible between the successes and the failures and I can't figure it out.

              Thanks,
              Bob

            • #680820

              Do you get the same result if you manually select a graphic & press Ctrl+Shift+F9? This might help narrow down the issue. I don’t really have an solution, though.

        • #680736

          I can’t explain the graphics disappearing; the macro works OK for me.

    • #680846

      Here’s a different approach:

      Sub UnlinkPictures()
      Dim intCount As Integer
      For intCount = ActiveDocument.Fields.Count To 1 Step -1
          With ActiveDocument.Fields(intCount)
              If .Type = wdFieldIncludePicture Then
                  .Update 're-grab the file (optional)
                  .Unlink 'lock it in
              End If
          End With
      Next
      End Sub

      The macro checks every field, working backwards from the end of the document, because the size of the fields collection keeps changing as you unlink the fields. A demo is attached. Note that these graphics were chosen at random and have no meaning relative to this question.

      • #681016

        The UnlinkPictures sub worked. Interestingly, I tried it without the Update method, and my graphics disappeared again. Using the Update method, the graphics appeared. I added a “Selection.Fields.Update” line to the code that Hans offered earlier, and it now works for me too.

        Thanks for all of your help,
        Bob

        “By dog, there’s more than one way to pluck a buzzard!” — Andy Griffith

    Viewing 1 reply thread
    Reply To: Batch embed of graphics (Word 2000 SR-1)

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

    Your information: