#1
|
|||
|
|||
Continuous Loop
Can anyone help me figure out why this loop is not stopping?
Selection.Find.ClearFormatting With Selection.Find .Text = "DO NOT PUBLISH ACTIVITY" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With While Selection.Find.Execute Selection.MoveUp Unit:=wdLine, Count:=1 Selection.SelectRow Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend With Selection.Font .Hidden = True End With Wend Much appreciated!!! |
#2
|
||||
|
||||
Hi cksm4,
Your code suggests you might be trying to hide the whole of the paragraph containing the string "DO NOT PUBLISH ACTIVITY". Is that correct? If it is, there's a much simpler way - a wildcard Find/Replace, where: Find = [!^13]{1,}DO NOT PUBLISH ACTIVITY[!^13]{1,}[^13] or, in vba parlance: .Text = "[!^13]{1,}DO NOT PUBLISH ACTIVITY[!^13]{1,}[^13]" .MatchWildcards = True
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hey Paul,
Thanks for the reply. I am trying to hide part of a table. I have the user insert quick parts as they input new activities. Each quick part adds new rows to the table. These are then compiled into a report. Some activities later become "irrelevant" to the final report and I want the user to be able to hide these prior to printing. To complicate it, I am using rich text controls to capture the data. I removed one of these activity tables, placed it on its own, removed all the paragraph marks in the table, and placed a paragraph mark before and after the table. I also placed one of my rich text controls with the target wording on its own as a secondary test. Using the following code the table and individual rich text control did not hide: Selection.Find.ClearFormatting With Selection.Find .Text = "[!^13]{1,}DO NOT PUBLISH ACTIVITY[!^13]{1,}[^13]" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False End With While Selection.Find.Execute Selection.Font.Hidden = True Wend I may be WAY off as I am new to VBA/macros. Am I using this code wrong? Or perhaps does it not work on tables and rich text controls??? Again, much appreciation for you help!!! Brock |
#4
|
||||
|
||||
Hi cksm4,
So what are you trying to hide - some of the text in a cell in the table, a whole cell in a table, a whole row in a table, or the whole table?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
I have 4 rows that include data for the activity. Each row has 1-8 cells. Each cell has a descriptive header and a rich text control right under it for input (all in one cell). The form starts with one table. If the user needs to add a second, third... etc activity, they click a command button that adds another 4 rows (inserting a quick part which is essentially a copy of the first four rows).
So to answer your question... I have a lot of flexibility. I can keep the four rows in separate tables or keep then appending into one table. Whatever works faster or more stable. |
#6
|
||||
|
||||
Hi cksm4,
Assuming you're appending rows, try the following: Code:
Sub Test() With ActiveDocument.Range With .Find .ClearFormatting .Text = "DO NOT PUBLISH ACTIVITY" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute End With Do While .Find.Found MsgBox .Text .MoveStart Unit:=wdRow, Count:=-1 .MoveEnd Unit:=wdRow, Count:=3 .Font.Hidden = True .Collapse wdCollapseEnd .Find.Execute Loop End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
I works!!! I would have never figured out to use MoveStart and MoveEnd. I've been working on this for HOURS. I also really like the message box. It works as a way to alert the user that they are about to publish the document with activities hidden. Great idea.
A big thanks from the other side of the globe in Texas!! Your expertise made my document work! |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do you imbed a continuous play mp3 into a ppt | Joe Damore | PowerPoint | 2 | 09-15-2010 11:13 PM |
Excel recovery loop problem | fatman57 | Excel | 1 | 09-08-2010 03:57 AM |
Creating text that scrolls continuous | Mogogo | PowerPoint | 0 | 02-04-2010 11:41 AM |
continuous sound | boutells | PowerPoint | 2 | 11-27-2009 12:06 AM |
Outlook 2003 restart in a loop | Stegel | Outlook | 0 | 06-29-2007 12:34 PM |