Document Name

L

Lorrie Burns

Hello,
I am using Word 2003. I want to run a macro on that will replace the
document property "Title" with the document Name. However, the problem I am
having is that I don't want to include the .doc in the property title.
How do I tell Word NOT to include the document type with the name?
Also, how do I continue running the macro until there are no more open docs
to process?
 
L

Lene Fredborg

The macro below may do what you want. It iterates through all documents in
the Documents collection (i.e. all open Word documents). If the extension is
".doc" or ".dot", the Title will be set to the file name without the
extension, else the Title will be set to the file name as is. Examples of
titles:
"Test.doc" will be applied the property title "Test"
"Test.dot" will be applied the property title "Test"
"Test.htm" will be applied the title "Test.htm"
A new and never saved "Document1" will be applied the title "Document1"

Sub ChangePropertyTitle()

Dim oDoc As Document
Dim strTitle As String

For Each oDoc In Documents
With oDoc
'Define the Title to use
Select Case Right(.Name, 4)
Case ".doc", ".dot"
'Set Title to Name without last 4 characters
strTitle = Left(.Name, Len(.Name) - 4)
Case Else
strTitle = .Name
End Select
'Insert as property Title
.BuiltInDocumentProperties(wdPropertyTitle) = _
strTitle
End With
Next oDoc
End Sub

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
L

Lorrie Burns

That's perfect, Thank you!!
--
Lorrie


Lene Fredborg said:
The macro below may do what you want. It iterates through all documents in
the Documents collection (i.e. all open Word documents). If the extension is
".doc" or ".dot", the Title will be set to the file name without the
extension, else the Title will be set to the file name as is. Examples of
titles:
"Test.doc" will be applied the property title "Test"
"Test.dot" will be applied the property title "Test"
"Test.htm" will be applied the title "Test.htm"
A new and never saved "Document1" will be applied the title "Document1"

Sub ChangePropertyTitle()

Dim oDoc As Document
Dim strTitle As String

For Each oDoc In Documents
With oDoc
'Define the Title to use
Select Case Right(.Name, 4)
Case ".doc", ".dot"
'Set Title to Name without last 4 characters
strTitle = Left(.Name, Len(.Name) - 4)
Case Else
strTitle = .Name
End Select
'Insert as property Title
.BuiltInDocumentProperties(wdPropertyTitle) = _
strTitle
End With
Next oDoc
End Sub

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 

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