Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Find Function (Word VBA 2003)

    Hi,

    Ive got a macro that, on closing a document, looks for a particular piece of text for the user to note, before going on and printing it for them. The relevant lines of script are below;

    If ActiveDocument.Bookmarks.Exists("COT") = True Then
    With Selection.Find
    .ClearFormatting
    .Text = "ACNO500000*00"
    .MatchWildcards = True
    .Execute
    End With
    ActiveDocument.Save
    Application.DisplayAlerts = False
    ActiveDocument.PrintOut
    End If

    The problem Ive got is that sometimes the user needs to correct the document, and it seems the correction is always quite a way down the document, lower than the text that is being search for.

    It seems that the above 'Selection.Find' function looks from wherever the cursor is on the document downwards, rather than looking at the document as a whole.

    Is there any amendment to the 'Selection.Find' function that can tell it to look at the document as a whole, i.e., both up and down from where the cursor is?

    Cheers.
    Lee

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find Function (Word VBA 2003)

    You could move to the start of the document before searching:
    <code>
    Selection.HomeKey Unit:=wdStory
    </code>
    But it's not clear to me what you're doing - you search for some text, then immediately save and print the document without giving the user a chance to do anything.

  3. #3
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: Find Function (Word VBA 2003)

    Hi Hans,

    Many thanks for that.

    The copy I gave is from my test system. The users have the print script line remmed out and they print themselves.

    Thanks again.

    Cheers.
    Lee

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •