[word] Find.execute On Individual Basis

  • Hello,
    Concerns MSWord:
    See also http://home.tiscali.nl/adsl2029/
    for detailed video demonstration of the problem.


    Task: find and change bold words with same words surrounded by bold tags: boldword = <b>boldword</b>
    Code used is shown below and runs fine until last boldword, which the procedure keeps selecting infinitely....


    Any solutions welcome
    Thanks:


    By the way code assumes tabel with content present.

  • Re: [word] Find.execute On Individual Basis


    This works but I'm sure there must be a cleaner way for this to be resolved.
    The .Wrap = wdFindStop should work but doesn't.
    [vba]Sub boldTags()
    'Er wordt een LxM tabel aanwezig verondersteld in het word document.
    'Elke cel kan een bold woord bevatten. Dit woord wordt dan gezocht en voorzien van
    'omringende tags.... bijvoorbeeld: <b>bold_woord</b>

    'boldWordFound zal steeds het gevonden bold woord bevatten
    Dim boldWord As String

    boldWord = ""

    'er is maar een enkele tabel en deze wordt geselecteerd
    ActiveDocument.Tables(1).Select

    'Binnen de selectie, gebruik Find als volgt
    With Selection.Find
    .Forward = True 'geeft de richting aan waarin gezocht wordt
    .Font.Bold = True 'geeft het bold type aan waarna gezocht zal worden
    .Wrap = wdFindStop
    '====HIER GAAT HET STRAKS MIS: bij het laatst gevonden boldWord blijft het programma loopen
    'zolang er bold text gevonden wordt doe hetvolgende
    Do While .Execute
    boldWord = .Parent.Text 'hiermee wordt de text in de variabele boldWord geplaats
    If InStr(1, .Parent.Text, "</b>") > 0 Then Exit Do
    .Parent.Text = "<b>" & boldWord & "</b>"
    'controle msgbox toont gevonden woord. Bij "loopen" de Cancel knop gebruiken om netjes af te sluiten
    If MsgBox("gevonden woord = " + boldWord, vbOKCancel) = vbCancel Then GoTo ENDSUB
    Loop

    End With

    ENDSUB:
    End Sub[/vba]

    [h4]Cheers
    Andy
    [/h4]

  • Re: [word] Find.execute On Individual Basis


    Thanks for your reply. This is a good workaround. The code is an extraction of a program I'm writing, that also deals with italic and underscore. So I have to check for either of them. I will put this check in a separate routine.


    Regards

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!