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 from VB6

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.

In most cases this works fine:

First 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.

I'd also like to populate the summary values in document properties if this is possible.

Thank you for any help.

Charlie
 
Hi Charlie,

Setting the default path can be problematic and there is no real way to set a default filename. You might find it better to carry on saving but to identify the file in some way which says that it is only 'your' version which has been saved - perhaps with a document property - so that next time round you can identify it and overwrite it if appropriate. For this, and your secondary question, take a look at the [blue]Document.BuiltInDocumentProperties[/blue] collection (and perhaps the [blue]Document.CustomDocumentProperties[/blue] collection).

Code along the lines of:

Set some property
Check if file exists (try opening it)
If it exists, check your property
If your property is true,
Close and delete the old doc,
Save your new one
If your property is false
Prompt the user in some way
If the user says go ahead anyway
Close and delete the old doc,
Save your new one
Else
Do nothing ??
Unset your property so that it will get removed at first user save

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
If the document template is in the same subfolder, you could create a template object, set it to ActiveDocument.AttachedTemplate, assign its path to a variable and read THAT variable for your purpose.

The document is then created by double clicking on the template and if it is not saved, no problem.

Hope that helps.

______________________________________
Eman2005
Technical User
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top