MS Office Forum / Word / Mailmerge and Fax / February 2007
More stupid INCLUDEPICTURE questions
|
|
Thread rating:  |
LAR - 01 Feb 2007 01:16 GMT 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::options::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
macropod - 01 Feb 2007 02:23 GMT 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
 Signature macropod [MVP - Microsoft Word]
| 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 [quoted text clipped - 25 lines] | | LAR LAR - 01 Feb 2007 03:13 GMT Cool! Thanks. I'll give it a try.
Is there a way with a macro to temporarily change the Active Document path (tools::options::file locations::documents)? Seems like that would be easier. But then what do I know.
> Hi LAR, > [quoted text clipped - 99 lines] > | > | LAR Peter Jamieson - 01 Feb 2007 03:14 GMT Worth trying the following, just in case...
{ INCLUDEPICTURE "{ filename \p }\\..\\{ MERGEFIELD picname }.jpg }
But a. although it appears to work here these sorts of construct make me nervous b. you may have to uncheck Word Tools|Options|General|"Web options"|Files|"Update links on save"
Peter Jamieson
>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 [quoted text clipped - 30 lines] > > LAR LAR - 01 Feb 2007 03:49 GMT Peter,
Thanks for the help. This is more what I was looking for. Seems like it should work. I have changed my INCLUDEPICTURE to your syntax below, and while the syntax works the pictures still load from the DOCUMENTS path in tools:options:files locations:documents. ???? It almost seems like I have some basic setting wrong that is making the INCLUDEPICTURE use that DOCUMENTS path.
Thanks again for taking a look.
> Worth trying the following, just in case... > [quoted text clipped - 41 lines] > > > > LAR Peter Jamieson - 01 Feb 2007 09:28 GMT Sorry LAR,
I had forgotten you were using Word 2000. I'll have a look at that version.
Peter Jamieson
> Peter, > [quoted text clipped - 59 lines] >> > >> > LAR Peter Jamieson - 01 Feb 2007 11:40 GMT OK, I have checked again on Word 2000 and it seems to work much the same way.
Can you check your INCLUDEPICTURE field /really/ carefully and make sure that the path it constructs from the various fields and text is identical to the path of the image you want to insert, other than having doubled-up backslashes. No extra spaces (easy to insert by accident when cutting/pasting)!
> Sorry LAR, > [quoted text clipped - 69 lines] >>> > >>> > LAR LAR - 01 Feb 2007 14:56 GMT Peter,
Thanks again for all your help. Here is what I have:
{ INCLUDEPICTURE "{FILENAME \p}\\..\\ {MERGEFIELD ML_Number}.jpg" }
... and here is what it resolves to for the first picture:
{ INCLUDEPICTURE "C:\Documents and Settings\Larry\Desktop\BuyerTourTest\BuyerTour.doc\\..\\60116398.jpg" }
The only difference I see between what I have and what you proposed is that I added the closing double quote after the .jpg.
As I said, I am trying to merge several pictures (4 in this test) into this document. I have all 4 in the folder with the main document but only 3 in the DOCUMENTS path folder. When I merge, only the 3 pictures in the DOCUMENTS path folder appear in the document.
Hopefully, someone with better eyes than I can see the error in my ways. Thanks again for spending all the time on this.
LAR
> OK, I have checked again on Word 2000 and it seems to work much the same > way. [quoted text clipped - 78 lines] > >>> > > >>> > LAR Peter Jamieson - 01 Feb 2007 15:05 GMT Larry,
You have a space befroe the { MERGEFIELD ) field in
> { INCLUDEPICTURE "{FILENAME \p}\\..\\ {MERGEFIELD ML_Number}.jpg" } Is it actually in there, or is that a typo?
The other one
> { INCLUDEPICTURE "C:\Documents and > Settings\Larry\Desktop\BuyerTourTest\BuyerTour.doc\\..\\60116398.jpg" } seems OK.
Peter Jamieson
> Peter, > [quoted text clipped - 115 lines] >> >>> > >> >>> > LAR Peter Jamieson - 01 Feb 2007 15:32 GMT I suspect with all this focus on the path name we've forgotten the other thing you have to do, which is: a. If you're outputting to a new document, select the content (ctrl-A) and press F9 to update all the fields b. If you're outputting to a printer, you have to check Word Tools|Options|Print|"Update links".
> Larry, > [quoted text clipped - 138 lines] >>> >>> > >>> >>> > LAR LAR - 02 Feb 2007 06:28 GMT Peter,
Thanks for the reminder, but yes I have been Ctrl-Aing and F9ing 'till the cows come home.
> I suspect with all this focus on the path name we've forgotten the other > thing you have to do, which is: [quoted text clipped - 145 lines] > >>> >>> > > >>> >>> > LAR LAR - 02 Feb 2007 06:27 GMT Typo. Sorry.
> Larry, > [quoted text clipped - 132 lines] > >> >>> > > >> >>> > LAR Peter Jamieson - 02 Feb 2007 08:50 GMT it sounds as if you've managed to work around the problems now, but exactly which version of Word 2000 are you using? My copy is Word 2000 SP3 on Win 2000. There have always been odd little problems with doubling/not doubling backslashes but they seemed mostly to disappear over time.
A couple of articles about settings that might affect this behaviour - although logically speaking, they shouldn't, are:
http://support.microsoft.com/kb/330079/en-us
http://support.microsoft.com/kb/171406/en-us
There are probably others...
Peter Jamieson
> Typo. Sorry. > [quoted text clipped - 152 lines] >> >> >>> > >> >> >>> > LAR macropod - 01 Feb 2007 06:59 GMT Hi Peter,
That works too. Neat trick!
Cheers
 Signature macropod [MVP - Microsoft Word]
| Worth trying the following, just in case... | [quoted text clipped - 41 lines] | > | > LAR Peter Jamieson - 01 Feb 2007 11:55 GMT Hi macropod,
I've constucted paths using { filename \p } before, e.g. where you have
folderx docy.doc docy.doc.folder docz.doc
and use
"{ filename \p }.folder\\docz.doc" to reference the .doc
but I don't think I've ever actually tried the \\..\\ thing before and am quite surprised that it creates a legit. pathname.
Because there's mixture of single backslashes and doubled backslashes in the constructed path name so it's a bit surprising that it works at all, anywhere, but then that's often the way with fields :-)
Peter Jamieson
> Hi Peter, > [quoted text clipped - 56 lines] > | > > | > LAR macropod - 01 Feb 2007 21:21 GMT Hi Peter,
Surprising indeed! And the code works equally well with '/../' instead of '\\..\\'.
I've done a bit of experimenting with the technique you described and find that it works with INCLUDETEXT, RD & HYPERLINK fields, but not with LINK fields..
The same approach can be extended to implement true relative addressing. For example: {INCLUDEPICTURE "{FILENAME \p}\\..\\My Pictures\\AdobeRGB.png"} looks in the current file's child folder named 'My Pictures' and: {INCLUDEPICTURE "{FILENAME \p}\\..\\AdobeRGB.png"} looks in the current file's parent folder, while: {INCLUDEPICTURE "{FILENAME \p}\\..\\..\\My Pictures\\AdobeRGB.png"} looks in the current file's parent folder, then the parent's child folder named 'My Pictures' (I guess you could call that a sibling folder).
Cheers
 Signature macropod [MVP - Microsoft Word]
| Hi macropod, | [quoted text clipped - 78 lines] | > | > | > | > LAR LAR - 02 Feb 2007 06:24 GMT Peter & Pod :-),
I haven't been able to get the syntax you are describing to work for me but here is what I have been able to get working. I created an AutoOpen Macro with the following code:
For Each aVar In ActiveDocument.Variables If aVar.Name = "MyPath" Then num = aVar.Index Next aVar If num = 0 Then ActiveDocument.Variables.Add Name:="MyPath", Value:=ActiveDocument.Path & "\" Else ActiveDocument.Variables(num).Value = ActiveDocument.Path & "\" End If ActiveDocument.Variables(num).Value = Replace(ActiveDocument.Variables(num).Value, "\", "\\")
My INCLUDEPICTURE looks list this: {INCLUDEPICTURE "{DOCVARIABLE "MyPath"}{MERGEFIELD picname}.jpg"
... and all is well. I can now move the main document to any folder and the merge works. Phew, that wasn't all that easy.
Thanks for all the help from all.
LAR
> Hi Peter, > [quoted text clipped - 96 lines] > | > | > > | > | > LAR Peter Jamieson - 02 Feb 2007 09:58 GMT > but not with LINK fields.. Yes, LINK fields have long been a bit different, probably with good reason.
Peter Jamieson
> Hi Peter, > [quoted text clipped - 114 lines] > | > | > > | > | > LAR
|
|
|