Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Word document name and path

Status
Not open for further replies.

CharlieSW10

Programmer
Apr 14, 2005
10
GB
I am using the Word 9.0 Object Library and VB 6 to populate a template document with values from an Access form.

The user can then edit the Word document to make any necessary changes before saving it to the directory where I want all these documents held.

At the moment this works fine in most cases:

1st I create the new document >
objWord.Documents.Add Template:=Templatedrivepathparameter & "Policycoverletter.dot", NewTemplate:=False, DocumentType:=0

Immediately afterwards I save it with the filename and path I want:
' objWord.ActiveDocument.SaveAs (Datadrivepathparameter & strPolicynumber)

The problem occurs when the user decides to back out of the Word document without saving. Unbeknown to the user I've already saved the document to set the document path and file name so if they try to run the mailmerge again they don't understand why a document already exists.

Is there any way I can use the Word Object library to set a default path and filename without actually saving the document, and then allow the user to save it using these defaults.

Thank you for any help.

Charlie
 
I've moved this question to the VB for Applications forum but would very much like to hear from you if you have any suggestions.

Charlie
 
Charlie, this should move to VBA forum if the work was to be done within word. If you are using VB6, then here is the place.
Co-incidently, I have done quite the same thing, except that I remotely run a word vba macro to do the filling.

You would not give the use the possibility to play with the template and then save as document, so you start by saving as document and THEN let the user work in the document. I do not think this was a wrong way to do it.
Now, to solve the problem of your 'what if...', one way could be this:
When you save the document, save it in a temporary location and check the save date and time properties. Store this in a document custom property of your creation. Then, using an AutoClose macro, you compare the save date and time of the just closed document with the custom property value. Only if they were not identical, save as the good name and path, and then delete the temporary copy, before closing.

Let me know if this helps, or if you need further assistance.

_______________________________________

Eman_2005
Technical Communicator
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top