Hi everyone,

I'm working on a macro which will take the text N (an abbreviated reference number) selected manually by the user in Doc1, open Doc2, which contains a complete list of referenced information, search for N and present the user with the full and correct reference. The goal is to check information against an authoritative list.

So far so good, but I want to check the initial selection for length and format to avoid people making nonsensical selections.

1. There must be a selection, so:

If Selection.Type <> wdSelectionNormal Then
   MsgBox ("Please select a reference number" & vbCrLf & "(example: 123/00) and try again.")
   End
Else
2. The selection must be at least 4 characters long, so:

If Len(N) < 4 Then
   MsgBox ("Oops. Please try again.")
   End
End If
3. It must have the format #/## (number-slash-number-number); there can be between 1 and 3 characters to the left of the slash (so ##/## and ###/## would be okay as well).

I suppose this can be done using wildcards, but i don't know how to get this into code.

A related question: would it be prefereable to assign the variable N right away (N = Selection.Text) before running the tests (as in 2), or should I run the tests directly on the Selection (as in 1)?

Thanks for your help and have a great day!

kobber