Re: Validation of text of bookmark entries by Senapathy
Senapathy
Mon Aug 09 08:03:53 CDT 2004
Hi Jonathan,
I managed that one now. What I did was basically scan to the right character
by character till the new line char, and kept extending the selection.
Finally I just trimmed and checked the Selection.Text against the new line
char.
E.g:
If ActiveDocument.Bookmarks.Exists(p_strField) = False Then
bInvalidReport = True
Else
Selection.GoTo What:=wdGoToBookmark, Name:=p_strField
Selection.MoveEnd Unit:=wdCharacter, Count:=1
strField = TrimTabs(Selection.Text)
While Right(strField, 1) <> Chr(13)
Selection.MoveEnd Unit:=wdCharacter, Count:=1
strField = Selection.Text
Wend
' Trim the selection of tabs and spaces
strField = TrimTabs(strField)
strField = Trim(strField)
' After trimming, if the resultant is just a newline char, it is an
empty field
If strField = Chr(13) Then
strInvalidFields = strInvalidFields + Chr(10) + p_strField
bInvalidReport = True
Selection.Collapse
Selection.Text = "Invalid!"
Selection.Font.Color = wdColorRed
End If
End If
Warm regards,
Sena
"Jonathan West" <jwest@mvps.org> wrote in message
news:u5DCCoffEHA.3632@TK2MSFTNGP09.phx.gbl...
> In that case, you need to describe exactly the criteria for deciding
whether
> the text to the right of the bookmark is empty or not. Once we can define
> this, it won't be that hard to write code to implement it.
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
>
> "Senapathy" <senapathy.k@siemens.com> wrote in message
> news:cf73j6$8uu$1@news.mch.sbs.de...
> > Hello Jonathan,
> >
> > Thanks for the post, I tried it out but unfortunately that doesn't work
> for
> > me either.
> > In the template that I have, the bookmarks are already created and they
> are
> > basically empty all the time. The bookmark is not a selection of some
> text.
> > So the check "If ActiveDocument.Bookmarks("bkMark").Empty Then"... this
> > basically yields empty = true all the time.
> > What I wanted is to read a few characters to the right of the concerned
> > bookmarks. If those are empty, then I would say that the entry against
the
> > bookmark is improper.
> >
> > If you would like to take a look at the template and the code that I
have,
> I
> > can send it to you. Please tell me if you would like to do that.
> >
> > Warm regards,
> > Sena
> >
> > "Jonathan West" <jwest@mvps.org> wrote in message
> > news:O%23Gx836eEHA.2440@tk2msftngp13.phx.gbl...
> > > Hi Senapathy,
> > >
> > > You can use the Empty property of the bookmark to check whether it is
> > > marking text, and then use the Text property of the bookmrk's range to
> > > extract the text if it is not empty, like this:
> > >
> > > If ActiveDocument.Bookmarks.Exists("bkMark") = False Then
> > > bInvalidReport = True
> > > strInvalidFields = strInvalidFields + Chr(10) + p_strField + "
"
> > > Else
> > > If ActiveDocument.Bookmarks("bkMark").Empty Then
> > > 'bookmark is empty
> > > Else
> > > strBookmark =
ActiveDocument.Bookmarks("bkMark").Range.Text
> > > End If
> > > End If
> > >
> > >
> > > --
> > > Regards
> > > Jonathan West - Word MVP
> > > www.intelligentdocuments.co.uk
> > > Please reply to the newsgroup
> > >
> > >
> > > "Senapathy" <senapathy.k@siemens.com> wrote in message
> > > news:cevqn1$f52$1@news.mch.sbs.de...
> > > > Hello,
> > > >
> > > > I am using VBA for Word to validate whether a report Word Doc is
fine.
> > > > For this, I scan through the doc for certain bookmarks.
> > > > If the bookmarks are not present at all, it is a major problem and I
> > > signal
> > > > error and return.
> > > >
> > > > If the bookmarks are present, I would like to read the text soon
after
> > the
> > > > bookmark and check if it is not empty. That is all.
> > > > But I am not able to do this.
> > > >
> > > > Can anyone point me how to do this?
> > > >
> > > > Currently the code that I use to scan for the bookmarks is thus:
> > > >
> > > > If ActiveDocument.Bookmarks.Exists("bkMark") = False Then
> > > > bInvalidReport = True
> > > > strInvalidFields = strInvalidFields + Chr(10) + p_strField +
"
> "
> > > > Else
> > > > ' TODO : Check for valid entries for the bookmarks
> > > > End If
> > > >
> > > > For the Checking for valid entries, I have tried the following
things,
> > > which
> > > > do not work:
> > > >
> > > > Selection.GoTo What:=wdGoToBookmark, Name:="bkMark"
> > > > If IsEmpty(Selection.Text) then
> > > > ....
> > > >
> > > > This doesn't work because even if there is nothing after the
bookmark
> > but
> > > > blank characters, the bookmark always contains some vague ASCII
> > character.
> > > >
> > > > If I try
> > > > ActiveDocument.Bookmarks.("bkMark").Empty = True
> > > > ....
> > > > then it always returns empty for me, indicating a problem with
> every
> > > > field.
> > > >
> > > > Warm regards,
> > > > Senapathy
> > > >
> > > >
> > >
> >
> >
>