#1
|
|||
|
|||
Never-ending loop
Hello! I have this macro that I made for a project. It searches for a image and rejects TC changes twice. The problem I have with it is that I can't make it stop at the end of the document so it continues looping until it starts rejecting changes in the text as well. Anybody know how to make it stop at the end of the document?
Thank you in advance! Code:
Sub Huh() ' ' Huh Macro ' ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting Do With Selection.Find .Text = "^g" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Range.Revisions.RejectAll Selection.NextRevision (True) Selection.Range.Revisions.RejectAll Selection.NextRevision (True) Loop End Sub Last edited by valentinator; 06-09-2022 at 12:33 PM. |
#2
|
||||
|
||||
What is the end-game you are trying to achieve? Are you trying to reject any tracked revisions which include a change to a graphic? Why do you want to do this twice?
What if the change is a deletion/addition of a graphic which includes adjacent text?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
I have two versions of a document and I need to place the image from the base file into the updated one. There are no graphs here, only images.
|
#4
|
||||
|
||||
Well that code doesn't look like it was intended to do that.
Are they exact matches, one for one? that is, as an example, does the tenth image in the target file need to be replaced by the tenth one in the source file?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Yes, every image corresponds to the same one in the base file, but newer file images are corrupt and show as blanks. I know it doesn't make sense, but it works for me in this specific case. :-)
I just need to make that loop end at the end of the document. |
#6
|
||||
|
||||
As I don't have a sample document to test on, I can't guarantee this would work but conceptually, this code will find graphics from the current selection forward and if the found graphic is marked as a tracked revision it rejects the change and searches for the next graphic.
Code:
Sub Huh() Dim aRng As Range Set aRng = Selection.Range aRng.End = ActiveDocument.Range.End With aRng.Find .ClearFormatting .Replacement.ClearFormatting .Text = "^g" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False Do While .Execute = True If aRng.Revisions.Count > 0 Then aRng.Revisions.RejectAll End If aRng.Collapse Direction:=wdCollapseEnd aRng.End = ActiveDocument.Range.End Loop End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Tags |
loop, macro |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Number series ending 50 and 100 | Marcia | Excel | 4 | 08-11-2021 02:36 PM |
Trying to count the number of cells ending with 001 or 002 | mgroessl | Excel Programming | 5 | 08-06-2019 03:39 PM |
how do you formulate the date by pay period ending? | crussell | Excel | 8 | 02-23-2016 07:38 AM |
Find and highlight all words ending in -ly | RBLampert | Word VBA | 13 | 10-23-2012 04:45 PM |
Paragraph ending in following page | tadlomc | Word | 1 | 01-18-2012 05:31 AM |