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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save name in Word XP 1

Status
Not open for further replies.

tilltek

Programmer
Mar 8, 2001
298
0
0
PH
Is there a <field> that can be used in Word XP that will supply a name for the document?
EG: Sometimes when you go to save a new doc, a name is suggested. It seems to be the first word in the doc but is there a way of setting that name.
Ken F
 
Hi TillTek,

You can put additional code in the standard Word functionality. This will open the File Save As Window with the documentname &quot;YourDocumentName.doc&quot;:

Sub FileSaveAs()

With Dialogs(wdDialogFileSaveAs)
.Name = &quot;YourDocumentName.doc&quot;
.Show
End With

End Sub

Regards,
Unica
 
Thanks Unica, but will it accept a field as the name?
I was hoping to be able to save a document under the company name, with the company name coming from the address.
Something like &quot;May 03 invoice &quot;+<company>+&quot;.doc

Do you think this can be done?

If I write a Word document and click on [save as], the system suggests the first word of the document so it must check the document to get this detail.
Ken F
 
Hi Ken,

yes it can be done. But you must have some reference to the company name. So either it has to be in a bookmark in your document or you must be 100% sure it is always the first word in your document. If it's the first word in your document you can build your documentname as follows:

Sub FileSaveAs()
Dim sDocName as string

sDocName = format(now,&quot;mmmm yyyy&quot;)
sDocName = sDocName & &quot; invoice&quot;
sDocName = sDocName & activedocument.Words(1)
sDocName = Trim(sDocName) & &quot;.doc&quot;

With Dialogs(wdDialogFileSaveAs)
.Name = sDocName
.Show
End With

End Sub

Regards,
Unica
 
Thanks Unica, that did it the trick.
It works as expected except for &quot;!Unexpected End of Formula&quot; showing up at the start of the document.
I have put a merge field containing the company name at the very start of the document and then formatted the text colour as white so it's not visible on the document.
Works fine. Thanks again.
Ken F
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top