Need help with code for pasting into dialog box field and...

S

Sharyn K

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!
 
S

Sharyn K

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?
 
S

Steve Yandl

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
 
S

Steve Yandl

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
 
H

Helmut Weber

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.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
S

Sharyn K

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
 
S

Steve Yandl

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
 
S

Steve Yandl

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
 

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