! Merge Fields to be used in Variables

W

Wembly

Hi,

I'm setting up a letter merge in Word and is being done
via VBA.

I want to be able to automatically save a file using a
particular field from the merged letter (a merged field).
E.g. when the user clicks on the save button, it saves it
using a concatenated string of two other variables namely
today's date and letter reference number (which also
appears on the merged letter).

Your help is greatly appreciated.

Wembly
 
J

Jezebel

You can trap Word's save function by writing a macro called FileSave. If
this macro exists, it runs in place of the built-in save command. In this
macro you check whether the file has been saved before and if not, set the
name to whatever it ought to be; then save it.

This is air-code, but along these lines --

With ActiveDocument

'Document never saved? (there's probably a better test than this)
If .Name <> .FullName then

'Make the file name
pFileName = LETTERFOLDER & _
format(Now, DATEFORMAT) & _
.CustomDocumentProperties(REFNUMBER)

? Check if this file exists already ....

'Save it
.SaveAs FileName:=pFileName

'Saved already
else
.Save
end if

end with

Add error-handling so you always know if it didn't work, otherwise you'll
lose documents now and again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top