borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (how to export msaccess table to msexcel sheet using visual basic?)Next Topic (Display data on access form) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : [word] Find.Execute hangs up
Poster Message
pieter.de.boer
Level: Trainee

Registered: 18-09-2006
Posts: 1

icon [word] Find.Execute hangs up

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.

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
    
    '====HIER GAAT HET STRAKS MIS: bij het laatst gevonden boldWord blijft het programma loopen
    'zolang er bold text gevonden wordt doe hetvolgende
    While .Execute
    boldWord = .Parent.Text    'hiermee wordt de text in de variabele boldWord geplaats
    .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
        
    Wend
    
End With

ENDSUB:
End Sub

18-09-2006 at 08:58 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : [word] Find.Execute hangs up
Previous Topic (how to export msaccess table to msexcel sheet using visual basic?)Next Topic (Display data on access form) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder