change document title created from template

D

Digital Services

Using Word 97 & VBA.

When creating a new document from a template the document is given the name
Document1 (or Document2 etc) in the title bar of the window.

Please would someone tell me how to set the document title to something of
my choice using VBA. Ideally I would like it to reflect the name of the
template. I was thinking of putting code in the AutoNew macro and using
document properties.

Many thanks.
 
D

Digital Services

Thanks for your reply.
I tried your suggestion, but it's not what I'm looking for.
I want the document title to change without saving the document and as soon
as the document is created. Is this possible?
 
J

Jonathan West

Digital Services said:
Thanks for your reply.
I tried your suggestion, but it's not what I'm looking for.
I want the document title to change without saving the document and as soon
as the document is created. Is this possible?

Ah, I see.

You can change the Caption property of the ActiveWindow object of the
document.

ActiveDocument.ActiveWindow.Caption = "My special name"

This has no effect on anything except the title of the window, so if you
want it also to become the default filename when the document is saved, you
will also have to set the filename by the method suggested in the article.
 
D

Digital Services

Many thanks for the solution Jonathan, it works perfectly.
Sorry for getting the Windows terminology wrong.

Now I have:

Sub AutoNew()
ActiveDocument.ActiveWindow.Caption = "My special name"
ActiveDocument.Saved = True
End Sub

The second line prevents the File Save prompt.

An alternative to the first line would be:

ActiveDocument.ActiveWindow.Caption = Left$(ActiveDocument.AttachedTemplate,
Len(ActiveDocument.AttachedTemplate) - 4))

to strip off the '.dot' of the filename.

Steve
 
Top