Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2011, 04:43 PM
cksm4 cksm4 is offline Continuous Loop Windows XP Continuous Loop Office 2007
Advanced Beginner
Continuous Loop
 
Join Date: Aug 2010
Posts: 48
cksm4 is on a distinguished road
Default 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!!!
Reply With Quote
  #2  
Old 01-06-2011, 06:54 PM
macropod's Avatar
macropod macropod is offline Continuous Loop Windows 7 32bit Continuous Loop Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 01-06-2011, 07:32 PM
cksm4 cksm4 is offline Continuous Loop Windows XP Continuous Loop Office 2007
Advanced Beginner
Continuous Loop
 
Join Date: Aug 2010
Posts: 48
cksm4 is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 01-06-2011, 08:08 PM
macropod's Avatar
macropod macropod is offline Continuous Loop Windows 7 32bit Continuous Loop Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 01-06-2011, 08:29 PM
cksm4 cksm4 is offline Continuous Loop Windows XP Continuous Loop Office 2007
Advanced Beginner
Continuous Loop
 
Join Date: Aug 2010
Posts: 48
cksm4 is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 01-06-2011, 08:44 PM
macropod's Avatar
macropod macropod is offline Continuous Loop Windows 7 32bit Continuous Loop Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
I've kept the -1 and +3 moves you originally had, but they might need adjustment to target the correct ranges.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 01-06-2011, 09:03 PM
cksm4 cksm4 is offline Continuous Loop Windows XP Continuous Loop Office 2007
Advanced Beginner
Continuous Loop
 
Join Date: Aug 2010
Posts: 48
cksm4 is on a distinguished road
Default

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!
Reply With Quote
Reply

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
Continuous Loop 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft