Generally, yes it is possible. If you want me to write it for you,
though, you're going to have to tell me what the "specified standard"
is.
The following example will accept numbers like 4.7 or 99.4 and will
reject everything else. The Like operator is a pattern-matching
function, and the expression that follows it is the pattern.
Dim CaseNumber As String
Dim DocFileName As String
Dim msg As String
msg = "The text you entered for the case number is not " & _
"in the right format. Please enter the correct number."
With ActiveDocument
' first check whether the bookmark exists
' (it could have been deleted)
If .Bookmarks.Exists("SaveFileNumber") Then
CaseNumber = .Bookmarks("SaveFileNumber").Range.Text
End If
' check that the string has the right format
Do While Not ((CaseNumber Like "#.#") Or _
(CaseNumber Like "##.#"))
' if not, ask user for correct value
CaseNumber = InputBox(msg, "Error")
If CaseNumber = "" Then Exit Sub ' canceled
Loop
DocFileName = .Bookmarks("DocFileName").Range.Text
End With
If the correct format is more complicated, the code that validates the
bookmark could be put into a separate function that just returns True
(the value is OK) or False (it doesn't match the requirement).
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Jay, what you've suggested is along the lines of what I'd like to do. Just
today, someone made an edit to a document and deleted the bookmark
DocFileName. I knew what had happened, but she was presented with the debug
screen. I can prevent that from happening by tucking the bookmark away in a
header where it's unlikely to be disturbed, but I never thought about
running a check in the code to make sure it existed. That would be better
practice, along with protecting the bookmark.
As for the CaseNumber format it's always ####-AB-######. By that I mean
it's always comprised of "Year" "-" "2 letter CaseType" "-" "6 digit number"
as in 2005-CT-000015 for example. I'm guessing that would require calling a
function to run this validation test. I've never done that before.
Roger
> Generally, yes it is possible. If you want me to write it for you,
> though, you're going to have to tell me what the "specified standard"
[quoted text clipped - 123 lines]
> >> >> Jay Freedman
> >> >> Microsoft Word MVP FAQ: http://word.mvps.org
Jay Freedman - 21 Jul 2005 01:54 GMT
Hi Roger,
Actually, that pattern is easier to check than one that might have a
variable number of characters. In the last macro I posted, replace the
lines
> Do While Not ((CaseNumber Like "#.#") Or _
> (CaseNumber Like "##.#"))
with this:
Do While Not (CaseNumber Like "####-[A-Z][A-Z]-######")
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
>Jay, what you've suggested is along the lines of what I'd like to do. Just
>today, someone made an edit to a document and deleted the bookmark
[quoted text clipped - 143 lines]
>> >> >> Jay Freedman
>> >> >> Microsoft Word MVP FAQ: http://word.mvps.org
Roger - 27 Jul 2005 17:56 GMT
Thank you Jay. That worked out perfect. I was able to add a similar check
for the other bookmark with a message box for input in case the bookmark's
not found.
> Hi Roger,
>
[quoted text clipped - 161 lines]
> >> >> >> Jay Freedman
> >> >> >> Microsoft Word MVP FAQ: http://word.mvps.org
Jay Freedman - 27 Jul 2005 22:17 GMT
Good, I'm glad you were able to get it to work. Thanks for letting me know.

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
> Thank you Jay. That worked out perfect. I was able to add a similar
> check for the other bookmark with a message box for input in case the
[quoted text clipped - 179 lines]
>>>>>>>> Jay Freedman
>>>>>>>> Microsoft Word MVP FAQ: http://word.mvps.org