View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default More stupid INCLUDEPICTURE questions

Hi LAR,

Word doesn't really support that. However, if you run the following 'ResetPaths' macro against the merged output, it will update all
the paths for you:

Option Explicit
Dim TrkStatus As Boolean ' Track Changes flag

Private Sub ResetPaths()
' This routine runs whenever the document is opened.
' It calls on the others to do the real work.
' Prepare the environment.
Call MacroEntry
' Make sure the document has been saved, so that it has a valid path
If ActiveDocument.Saved = False then ActiveDocument.Save
' Most of the work is done by this routine.
Call UpdateFields
ActiveDocument.Save
' Go to the start of the document
Selection.HomeKey Unit:=wdStory
' Clean up and exit.
Call MacroExit
End Sub

Private Sub MacroEntry()
' Store current Track Changes status, then switch off temporarily.
With ActiveDocument
TrkStatus = .TrackRevisions
.TrackRevisions = False
End With
' Turn Off Screen Updating temporarily.
Application.ScreenUpdating = False
End Sub

Private Sub MacroExit()
' Restore original Track Changes status
ActiveDocument.TrackRevisions = TrkStatus
' Restore Screen Updating
Application.ScreenUpdating = True
End Sub

Private Sub UpdateFields()
' This routine sets the new path for external links.
Dim oRange As Word.Range
Dim oField As Word.Field
Dim OldPath As String
Dim NewPath As String
' Set the new path
NewPath = Replace$(ActiveDocument.Path, "\", "\\")
' Go through all story ranges in the document, including shapes,
' headers & footers.
For Each oRange In ActiveDocument.StoryRanges
' Go through the fields in the story range.
For Each oField In oRange.Fields
With oField
' Process IncludePicture fields only
If .Type = wdFieldIncludePicture Then
' Alternatively process all fields that have links to external files
' If Not .LinkFormat Is Nothing Then
' Get the old path
OldPath = Replace(.LinkFormat.SourcePath, "\", "\\")
' Replace the link to the external file
.Code.Text = Replace(.Code.Text, OldPath, NewPath)
End If
End With
Next oField
Next oRange
End Sub

Amongst other things, the macro gives feedback on its progress. If you look through the code, you'll see that it only acts on
IncludePicture fields, but has commented-out code you could use instead to process all fields that have links to external files.

Cheers

--
macropod
[MVP - Microsoft Word]


"LAR" wrote in message ...
| I am now trying to use the INCLUDEPICTURE field to insert pictures into my
| mail merge document. I would like to be able to merge pictures into the
| document that are in the same folder as the main document. Here is what I
| have tried and seen.
|
| I have successfully merged the pictures by using the entire path to the
| picture using something like {INCLUDE PICTURE "C:/temp/{MERGEFIELD
| picname}.jpg" \* MERGEFORMAT}. However, I want to be able to use the
| "current folder" to merge the pictures from.
|
| I have tried {INCLUDE PICTURE "{MERGEFIELD picname}.jpg" \* MERGEFORMAT}
| only to find that WORD uses the DOCUMENTS path (Tools:ptions::file
| locations::documents) as the path for the merged files. I know this because
| I have moved some of the pictures into the DOCUMENTS path folder and only the
| pictures that I move there appear in the merged document.
|
| I tried to use a relative path with things like {INCLUDE PICTURE
| "../{MERGEFIELD picname}.jpg" \* MERGEFORMAT} with no luck.
|
| I've looked at all the VBA examples for AutoOpen but could find nothing the
| TEMPORAIRLY changed the DOCUMENTS path to that of the source (main) document.
|
| So now, here I am again, asking how to accomplish what seems like a simple
| task (merge the pictures in the current folder into my document) that I can't
| seem to figure out for myself.
|
| Thanks in advance for any thoughts for ideas.
|
| LAR