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

    Search, instr check > next step (WordXP SP3)

    Hello

    I need to write some code that searches in a document for a particular dynamic string, if the search is correct then format the selection, otherwise move along to the next search.

    The search text will always start with an open square bracket and end with a closing square bracket [text.here] eg
    [CLO.0004.0026.0001]

    Within the one document the search strings will vary and I will need to search all these types of strings and format accordingly eg search for & format ....
    [CLO.0004.0026.0001]
    [ECLO.0004.0026.0001.00005]
    [OMI.0001.0002.0003.00004] + other formats

    I did notice the document may contain text in open & close square brackets that i dont want eg [Attachment 1] or [Attachment 8]

    any suggestions on how I can do this?
    diana

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

    Re: Search, instr check > next step (WordXP SP3)

    Do you want to format all strings encloses in square brackets except for some explicitly listed exceptions, or do you want to format some specific strings in square brackets?

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

    Re: Search, instr check > next step (WordXP SP3)

    hello hans

    your've explained it alot easier ....
    yes i want format all strings enclosed in square brackets except for some explicitly listed exceptions.

    cheers diana

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

    Re: Search, instr check > next step (WordXP SP3)

    Try this, adapt as needed.

    Sub FormatInBrackets()
    Dim arrExceptions(1 To 2) As String
    Dim i As Long
    Dim f As Boolean
    arrExceptions(1) = "<!t>[Exception1]<!/t>"
    arrExceptions(2) = "<!t>[Exception2]<!/t>"
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWildcards = True
    .Text = "<!t>[*]<!/t>"
    .Replacement.Text = "^&"
    .Replacement.Font.Bold = True
    Do While .Execute
    f = False
    For i = LBound(arrExceptions) To UBound(arrExceptions)
    If Selection.Text = arrExceptions(i) Then
    f = True
    Exit For
    End If
    Next i
    If f = False Then
    .Execute Replace:=wdReplaceOne
    End If
    Loop
    End With
    End Sub

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

    Re: Search, instr check > next step (WordXP SP3)

    hey hans

    nice one... :-)

    is there a way to test if the current selection is a hyperlink?
    as whats happening is there are multiple instances of the reference in the document. eg 3 lots of CLO.123.123
    it finds teh 1st instance and converts it to a hyperlink, and the next find locates the hyperlink.

    many thanks diana

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

    Re: Search, instr check > next step (WordXP SP3)

    You can test if the selection is (or rather contains) a hyperlink as follows:

    If Selection.Hyperlinks.Count > 0 Then

    You can test that the selection isn't (or rather doesn't contain) a hyperlink as follows:

    If Selection.Hyperlinks.Count = 0 Then

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

    Re: Search, instr check > next step (WordXP SP3)

    OK thankyou Hans I'll give that ago!

    many thanks
    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
  •