To use it, simply extract the file from the zip archive, open up the Word VBE (Alt-F11) and import the file into the document you want to use it with, then save the document. It doesn't work with LINK fields because they have the nasty habit of converting any embedded fields to plain text immediately they're updated.Īlso attached is a macro I've created for automatically updating the field paths for DATABASE, INCLUDEPICTURE, INCLUDETEXT, RD, and HYPERLINK as well as with LINK fields and for other linked objects. The above solution works with DATABASE, INCLUDEPICTURE, INCLUDETEXT, RD and HYPERLINK fields, but not with LINK fields - for which, see below. You can omit that part if you're working with multiple kinds of links, except for LINK fields.
By surfing the net to find example macros and piecing together the relevant bits, here's what I've come up with so far: Sub InsertPicture () Dim Doc As Dialog.
Note 3: The reason for the 'INCLUDEPICTURE "' copying & cutting is to avoid updating other kinds of links. Dear all, I am a VBA novice trying to write code to insert a picture and the filename as a caption.
Press Ctrl-A then F9 to update the fields.ġ1. Copy '\\Images' and paste it into the 'Find' box.ġ0.
This puts them in the Windows Clipboard.ħ. Cut the 'INCLUDEPICTURE "' and FILENAME field from the document. Create a FILENAME field, with the path switch (see above) and insert 'INCLUDEPICTURE "' into the document immediately before it.Ĥ. Copy 'INCLUDEPICTURE "C:\\Users\\UserName\\Documents' and paste it into the 'Find' box. Press Alt-F9 to reveal the field codes.Ģ. In this case, the images are in a child folder hanging off the 'Documents' folder. The following example employs an INCLUDEPICTURE field, but works equally well with DATABASE, INCLUDETEXT, RD and HYPERLINK fields.įirst off, insert a FILENAME field, with the path switch You can create this by pressing Ctrl-F9 (Cmd-F9 on a Mac) to create a pair of field braces anywhere in your document, then typing 'FILENAME \p' between them so that you end up with '. For LINK fields, scroll to the bottom of this thread. Well, there is a solution (based on an idea originally developed by Peter Jamieson, another MS Word MVP) that works with DATABASE, INCLUDEPICTURE, INCLUDETEXT, RD and HYPERLINK fields, but not with LINK fields. The only version I know of that doesn't always do this is Word 2010 - and even that seems to vary according to whether the path has ever been stored. Even if you omit the path from the field code, in most Word versions it still gets stored in the file's metadata. What is needed is a means of coercing Word into applying some sort of relative path addressing for fields pointing to other files. This means that, should you need to move the files as a group to another folder (eg putting them on a CD or USB stick for portability), all the links will break. The fields affected by this include Word's DATABASE, INCLUDEPICTURE, INCLUDETEXT, LINK, RD and HYPERLINK fields. Update - I also tried this approach, which seems to use cut-and-paste, but the results are the same.Word tends to store paths to external files with absolute paths. InitialFileName = currentPath & "\" & "*.rtf" Title = "Select the File that you want to insert" Set FileBox = Application.FileDialog(msoFileDialogFilePicker) I thought the correct approach would use the InsertFile method, but I can't figure it out.Īny pointers would be appreciated (I'm new to both Word and VBA). I wrote a macro that does most of this, but it fails to merge the formatting and drops (or hides) the header and footer. If I open and save the template file, open the file to insert, select all, and paste special with "merge formatting", then I get exactly what I want. Also, I would like to merge the formatting so that I keep the header and formatting from the template file, and the pictures in the. I would like to write a macro to fill this template with the contents of an. I have a template with a header/footer and text formatting.