I am a transcriptionist, and my client requires the patient name to be in the
file properties Title field of each file I create. I have some code (some of
it created by me, some not) that will copy the patient name from the report
and open the correct dialog box, but I can't figure out how to get it to
paste the name in the title field. I'm no programmer and need to be pointed
in the right direction at the very least!
Also, is there a way to have the file properties dialog box open when I
click to close the file so that I can confirm that I put the patient name in
there?
Here is the code I have so far:
Sub Copyname()
'
' Copyname Macro
' Macro recorded 6/14/2007
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Patient:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="$"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "$"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
With Dialogs(wdDialogFileSummaryInfo)
.Display
MsgBox .Title
End With
End Sub
Thanks with any help you can give!
Sharyn K - 28 Sep 2007 18:55 GMT
On further testing, the code below does not "keep" what I input into the
Title field when I use this macro, so perhaps the Dialog code needs to be
changed as well?
> I am a transcriptionist, and my client requires the patient name to be in the
> file properties Title field of each file I create. I have some code (some of
[quoted text clipped - 59 lines]
>
> Thanks with any help you can give!
Helmut Weber - 28 Sep 2007 20:11 GMT
Hi Sharyn,
setting a document's property
and saving the document immediatly afterwards
doesn't save the document's property.
Try:
activedocument.saved = false
activedocument.save
reopen it for a check.

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Sharyn K - 28 Sep 2007 21:06 GMT
Thanks Helmut, I appreciate that.
> Hi Sharyn,
>
[quoted text clipped - 7 lines]
>
> reopen it for a check.
Steve Yandl - 28 Sep 2007 19:47 GMT
Sharyn,
You don't need to run the dialog box to set the property.
If I read what you have correctly, the line where you have the word
"Patient:" has the patients name on the remainder of the line and nothing
else. That is to be the document title. See if what I have below does what
you want.
_________________
Sub AddTitleProperty()
Dim oRngA As Range
Dim oRngEnd As Range
Dim strName As String
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Text = "Patient:"
.Execute
End With
Set oRngA = Selection.Range
.EndKey Unit:=wdLine, Extend:=wdMove
Set oRngEnd = Selection.Range
End With
oRngA.End = oRngEnd.End
strName = Mid(oRngA.Text, 10)
ThisDocument.BuiltInDocumentProperties(1) = strName
End Sub
_________________
For your second request, try this short routine below. In the project
window at the upper left of the VBE window, you will need to right click
"This Document" and choose "Show Code" so the event procedure goes in the
document rather than a module.
________________________
Private Sub Document_Close()
Dialogs(wdDialogFileSummaryInfo).Show
End Sub
_______________________
Steve
>I am a transcriptionist, and my client requires the patient name to be in
>the
[quoted text clipped - 64 lines]
>
> Thanks with any help you can give!
Steve Yandl - 28 Sep 2007 20:01 GMT
Sharyn,
After I posted, I thought that you're probably storing this subroutine in
Normal.dot, the global template. That being the case, the last line of the
subroutine that says
ThisDocument.BuiltInDocumentProperties(1) = strName
should be changed to
ActiveDocument.BuiltInDocumentProperties(1) = strName
Steve
> Sharyn,
>
[quoted text clipped - 115 lines]
>>
>> Thanks with any help you can give!
Sharyn K - 28 Sep 2007 21:05 GMT
Steve, the title properties works great, thanks! Is there anyway to have
the document_close routine work with all files or with templates? I am
working from templates and I have only been successful getting this to work
when I place the code into a specific project's This Document - not the
Normal.
Thanks a bunch,
Sharyn
> Sharyn,
>
[quoted text clipped - 126 lines]
> >>
> >> Thanks with any help you can give!
Steve Yandl - 28 Sep 2007 21:26 GMT
Sharyn,
If you're only working with a small set of templates, you could open the
templates as documents, place the subroutine, and save the change to the
template.
A better approach is probably to create an add-in and place the sub there.
This article should be fairly easy to follow for instructions:
http://word.mvps.org/FAQs/MacrosVBA/PseudoAutoMacros.htm
Steve
> Steve, the title properties works great, thanks! Is there anyway to have
> the document_close routine work with all files or with templates? I am
[quoted text clipped - 146 lines]
>> >>
>> >> Thanks with any help you can give!
Sharyn K - 28 Sep 2007 22:39 GMT
Thanks Steve, you have been a tremendous help.
> Sharyn,
>
[quoted text clipped - 158 lines]
> >> >>
> >> >> Thanks with any help you can give!
Steve Yandl - 28 Sep 2007 21:39 GMT
Sharyn,
While I prefer using "ActiveDocument.BuiltInDocumentProperties(1)" as in the
subroutine I gave you, had you really wanted to use the dialog box, an
alternate approach would have been:
strPatientName = "John Smith"
With Dialogs(wdDialogFileSummaryInfo)
.Title = strPatientName
.Execute
End With
Steve
> Steve, the title properties works great, thanks! Is there anyway to have
> the document_close routine work with all files or with templates? I am
[quoted text clipped - 146 lines]
>> >>
>> >> Thanks with any help you can give!