From: Harish Sharma on 7 Feb 2010 02:10 Thanks Fumie2 for your prompt response. UserForm1 and WhiteList is automatically loaded during the startup. and the default is set as hidden, it is enabled only after all the subroutines are completed. I think I have found out what is causing this to run correctly in one file and incorrectly in other file-- when a colored words are present in paragraph, it runs correctly and when it is present in a table it goes into infinite loop. Can you help me to fix it. In the below subroutine, I have done UserForm1.Show for debuging purpose, it is not desired here, I just need to add all the colored text into the list box inside the loop and exit after all are added. With CURRENT_DOCUMENT.Find > .ClearFormatting > .Font.Color = wdColorRed > Do While .Execute(findText:="", Forward:=True, Format:=True) = True > UserForm1.WhiteList.AddItem (.Parent) > DoEvents > Loop > End With WhiteList if the userform is not loaded yet. OR.. > .have you loaded it, Done a Hide? "Fumei2 via OfficeKB.com" wrote: > Just thought of something. You have Userform1.WhiteList.Add BEFORE Userform1. > Show. > > How can you add anything to WhiteList if the userform is not loaded yet. OR.. > .have you loaded it, Done a Hide? > > Fumei2 wrote: > >More details required. This puts the .Found of the .Find into a listbox on a > >userform. > > > >What document has the userform? Is, in fact, the document you are searching > >the document that has the userform? I am not following how another document > >is involved. > > > >What fires Sub FindColored? Something on the userform? Something else? > > > >>Hi, > >> > >[quoted text clipped - 25 lines] > >> > >>thanks, > > -- > Message posted via OfficeKB.com > http://www.officekb.com/Uwe/Forums.aspx/word-programming/201002/1 > > . >
From: Pesach Shelnitz on 7 Feb 2010 03:54 Hi Harish, You can eliminate the infinite loop that starts when your macro finds colored text within a table by moving the boundaries of your Range object foward before starting the next cycle of the loop. One way to accomplish this is to collapse the range and advance the start by one character. The following modified version of your macro illustrates this without calling methods of your UserForm object. Sub FindColoredText() Dim CURRENT_DOCUMENT As Range Dim MyList As String MyList = "" Set CURRENT_DOCUMENT = ActiveDocument.Content With CURRENT_DOCUMENT.Find .ClearFormatting .Font.Color = wdColorRed Do While .Execute(findText:="", Forward:=True, Format:=True) = True MyList = MyList & .Parent & vbCrLf CURRENT_DOCUMENT.Collapse Direction:=wdCollapseEnd CURRENT_DOCUMENT.MoveStart Unit:=wdCharacter, Count:=1 Loop End With MsgBox MyList Set CURRENT_DOCUMENT = Nothing End Sub -- Hope this helps, Pesach Shelnitz My Web site: http://makeofficework.com "Harish Sharma" wrote: > > Thanks Fumie2 for your prompt response. UserForm1 and WhiteList is > automatically loaded during the startup. and the default is set as hidden, it > is enabled only after all the subroutines are completed. > > I think I have found out what is causing this to run correctly in one file > and incorrectly in other file-- when a colored words are present in > paragraph, it runs correctly and when it is present in a table it goes into > infinite loop. Can you help me to fix it. > > In the below subroutine, I have done UserForm1.Show for debuging purpose, it > is not desired here, I just need to add all the colored text into the list > box inside the loop and exit after all are added. > > With CURRENT_DOCUMENT.Find > > .ClearFormatting > > .Font.Color = wdColorRed > > Do While .Execute(findText:="", Forward:=True, Format:=True) = True > > UserForm1.WhiteList.AddItem (.Parent) > > DoEvents > > Loop > > End With > > > > WhiteList if the userform is not loaded yet. OR.. > > .have you loaded it, Done a Hide? > > > > > "Fumei2 via OfficeKB.com" wrote: > > > Just thought of something. You have Userform1.WhiteList.Add BEFORE Userform1. > > Show. > > > > How can you add anything to WhiteList if the userform is not loaded yet. OR.. > > .have you loaded it, Done a Hide? > > > > Fumei2 wrote: > > >More details required. This puts the .Found of the .Find into a listbox on a > > >userform. > > > > > >What document has the userform? Is, in fact, the document you are searching > > >the document that has the userform? I am not following how another document > > >is involved. > > > > > >What fires Sub FindColored? Something on the userform? Something else? > > > > > >>Hi, > > >> > > >[quoted text clipped - 25 lines] > > >> > > >>thanks, > > > > -- > > Message posted via OfficeKB.com > > http://www.officekb.com/Uwe/Forums.aspx/word-programming/201002/1 > > > > . > >
From: Harish Sharma on 8 Feb 2010 04:34
Pesach, Thank you so much for the fix, it worked! Harish "Pesach Shelnitz" wrote: > Hi Harish, > > You can eliminate the infinite loop that starts when your macro finds > colored text within a table by moving the boundaries of your Range object > foward before starting the next cycle of the loop. One way to accomplish this > is to collapse the range and advance the start by one character. The > following modified version of your macro illustrates this without calling > methods of your UserForm object. > > Sub FindColoredText() > Dim CURRENT_DOCUMENT As Range > Dim MyList As String > > MyList = "" > Set CURRENT_DOCUMENT = ActiveDocument.Content > With CURRENT_DOCUMENT.Find > .ClearFormatting > .Font.Color = wdColorRed > Do While .Execute(findText:="", Forward:=True, Format:=True) = True > MyList = MyList & .Parent & vbCrLf > CURRENT_DOCUMENT.Collapse Direction:=wdCollapseEnd > CURRENT_DOCUMENT.MoveStart Unit:=wdCharacter, Count:=1 > Loop > End With > MsgBox MyList > Set CURRENT_DOCUMENT = Nothing > End Sub > > -- > Hope this helps, > Pesach Shelnitz > My Web site: http://makeofficework.com > > > "Harish Sharma" wrote: > > > > > Thanks Fumie2 for your prompt response. UserForm1 and WhiteList is > > automatically loaded during the startup. and the default is set as hidden, it > > is enabled only after all the subroutines are completed. > > > > I think I have found out what is causing this to run correctly in one file > > and incorrectly in other file-- when a colored words are present in > > paragraph, it runs correctly and when it is present in a table it goes into > > infinite loop. Can you help me to fix it. > > > > In the below subroutine, I have done UserForm1.Show for debuging purpose, it > > is not desired here, I just need to add all the colored text into the list > > box inside the loop and exit after all are added. > > > > With CURRENT_DOCUMENT.Find > > > .ClearFormatting > > > .Font.Color = wdColorRed > > > Do While .Execute(findText:="", Forward:=True, Format:=True) = True > > > UserForm1.WhiteList.AddItem (.Parent) > > > DoEvents > > > Loop > > > End With > > > > > > > > WhiteList if the userform is not loaded yet. OR.. > > > .have you loaded it, Done a Hide? > > > > > > > > > > "Fumei2 via OfficeKB.com" wrote: > > > > > Just thought of something. You have Userform1.WhiteList.Add BEFORE Userform1. > > > Show. > > > > > > How can you add anything to WhiteList if the userform is not loaded yet. OR.. > > > .have you loaded it, Done a Hide? > > > > > > Fumei2 wrote: > > > >More details required. This puts the .Found of the .Find into a listbox on a > > > >userform. > > > > > > > >What document has the userform? Is, in fact, the document you are searching > > > >the document that has the userform? I am not following how another document > > > >is involved. > > > > > > > >What fires Sub FindColored? Something on the userform? Something else? > > > > > > > >>Hi, > > > >> > > > >[quoted text clipped - 25 lines] > > > >> > > > >>thanks, > > > > > > -- > > > Message posted via OfficeKB.com > > > http://www.officekb.com/Uwe/Forums.aspx/word-programming/201002/1 > > > > > > . > > > |