Results 1 to 6 of 6
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    test if bookmark empty (XP SP3)

    Hi

    How do i test if a bookmark or string is empty?
    I've been working with the function ISEmpty and ISNull. However the contents of my string may only be a paragraph mark, meaning theres no text data, therefore these functions return True.

    diana

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

    Re: test if bookmark empty (XP SP3)

    Strictly speaking, a string or bookmark containing a paragraph mark is not empty. If you want to test if a string or bookmark is empty except for paragraph or line breaks, you can use the following function:

    Function HasNoText(ByVal strText As String) As Boolean
    ' Remove paragraph breaks
    strText = Replace(strText, Chr(13), "")
    ' Remove manual line breaks
    strText = Replace(strText, Chr(11), "")
    ' Test if anything is left
    HasNoText = (Len(strText) = 0)
    End Function

    If you also want to exclude section breaks and manual page breaks, add a check for Chr(12). Use this function as follows on a bookmark:

    MsgBox HasNoText(ActiveDocument.Bookmarks("MyBookmark").R ange.Text)

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: test if bookmark empty (XP SP3)

    HI Hans

    thanks hans for your function - it works.
    yes i had a feeling that a paragraph mark was a valid string, but wasnt sure if a microsoft function already exists to test this scenario.

    diana

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: test if bookmark empty (XP SP3)

    Hi Hans

    Im working within a table. When selecting the cell, the other Char chacter being selected is the Cell character. Is there a Character code for a cell?
    (my VBA help keeps displaying the error message 'Internet Explorere Script Error' - mk:@MSITStore:C:PROGRA~1COMMON~1MICROS~1VBAVBA6103 3VbLR6.chm::/html/vafctChr.htm' .....another thing to look at)

    diana

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

    Re: test if bookmark empty (XP SP3)

    The end-of-cell marker is Chr(7), so you can add a line to the function to remove Chr(7) as well.

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: test if bookmark empty (XP SP3)

    cheers Hans - that worked - Diana :-)

Posting Permissions

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