Results 1 to 11 of 11
  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    146
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Batch embed of graphics (Word 2000 SR-1)

    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

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

    Re: Batch embed of graphics (Word 2000 SR-1)

    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.

  3. #3
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    146
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch embed of graphics (Word 2000 SR-1)

    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

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

    Re: Batch embed of graphics (Word 2000 SR-1)

    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.

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

    Re: Batch embed of graphics (Word 2000 SR-1)

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

  6. #6
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    146
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch embed of graphics (Word 2000 SR-1)

    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

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch embed of graphics (Word 2000 SR-1)

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

  8. #8
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    146
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch embed of graphics (Word 2000 SR-1)

    <<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

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch embed of graphics (Word 2000 SR-1)

    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.

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Batch embed of graphics (Word 2000 SR-1)

    Here's a different approach:
    <pre>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</pre>

    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.
    Attached Files Attached Files

  11. #11
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    146
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch embed of graphics (Word 2000 SR-1)

    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

Posting Permissions

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