Thank you Graham and Greg,
I'll be studying this, along with a post in a related thread by Shauna
Kelley, to try to learn more about VBA. More than 10 years ago, I did a
fair amount of programming during the days of DOS in both Powerbasic and
two implementations of WordPerfect macro command language (version 5x
and 6x). Version 6x was a real programming language, not a recorder, and
5x had if-then statements, variables, etc. Both were procedural, and 6x
was modular, as was Powerbasic. But I never really attempted anything
that had object-oriented concepts or a lot of GUI, and I am a bit thrown
by it all with its concept of containers, methods, properties, etc.
Little by little, I'll get the basic concept down.
So thanks for your patience with an old guy trying to learn something new.
Regards,
Alan Stancliff
Alan Stancliff wrote:
> 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/eonojSFcIHA.1960@TK2MSFTNGP02.phx.gbl
> If you use a browser:
> http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.word.vba.general&tid=f3baadfe-daeb-4809-9368-f0d5981d8cac&cat=en_US_eb67b351-9403-4888-a42c-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