A
Alan Stancliff
This is a question related to Word 2003 and VBA
I posed this question in an earlier thread, but it was needlessly
complicated and wordy. Here's a clearer way of formulating my question,
perhaps. I hope I'm not breaking any good netizen conventions here.
This is the previous thread:
If you use a newsreader:
news://msnews.microsoft.com:119/[email protected]
If you use a browser:
http://www.microsoft.com/communitie...b2b58efec0aa&lang=en&cr=US&sloc=en-us&m=1&p=1
Right now, I have a routine that, in part, finds a medical record number
at the top of a document and creates an autocorrect entry for it. I put
it together with macro record and some hints from this forum. The way it
works is that the cursor jumps to the top of the document, finds the
words "Medical Record Number", selects the medical record number, which
is located just to the right, and assigns it to an autocorrect entry MRN.
I'd like to do that without relying on the dialog box, which causes
things to jump around. Assume my cursor is in section 2 and I want it to
stay that way at the end of the macro's run. How would I do that?
Here is the sample code:
Sub MyDemo()
'
' go to top of section
'
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=1,
Name:=""
'
' find medical record number
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Medical Record Number: "
.Forward = True
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdWord, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
'
'Assign to Autocorrect entry mrn
'
AutoCorrect.Entries.Add Name:="mrn", Value:=Selection.Text
Selection.EndKey Unit:=wdLine
End Sub
Regards,
Alan
I posed this question in an earlier thread, but it was needlessly
complicated and wordy. Here's a clearer way of formulating my question,
perhaps. I hope I'm not breaking any good netizen conventions here.
This is the previous thread:
If you use a newsreader:
news://msnews.microsoft.com:119/[email protected]
If you use a browser:
http://www.microsoft.com/communitie...b2b58efec0aa&lang=en&cr=US&sloc=en-us&m=1&p=1
Right now, I have a routine that, in part, finds a medical record number
at the top of a document and creates an autocorrect entry for it. I put
it together with macro record and some hints from this forum. The way it
works is that the cursor jumps to the top of the document, finds the
words "Medical Record Number", selects the medical record number, which
is located just to the right, and assigns it to an autocorrect entry MRN.
I'd like to do that without relying on the dialog box, which causes
things to jump around. Assume my cursor is in section 2 and I want it to
stay that way at the end of the macro's run. How would I do that?
Here is the sample code:
Sub MyDemo()
'
' go to top of section
'
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=1,
Name:=""
'
' find medical record number
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Medical Record Number: "
.Forward = True
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdWord, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
'
'Assign to Autocorrect entry mrn
'
AutoCorrect.Entries.Add Name:="mrn", Value:=Selection.Text
Selection.EndKey Unit:=wdLine
End Sub
Regards,
Alan