Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-09-2022, 08:30 AM
valentinator valentinator is offline Never-ending loop Windows 10 Never-ending loop Office 2019
Novice
Never-ending loop
 
Join Date: Jun 2022
Posts: 9
valentinator is on a distinguished road
Unhappy 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.
Reply With Quote
  #2  
Old 06-09-2022, 08:54 PM
Guessed's Avatar
Guessed Guessed is offline Never-ending loop Windows 10 Never-ending loop Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 06-09-2022, 09:13 PM
valentinator valentinator is offline Never-ending loop Windows 10 Never-ending loop Office 2019
Novice
Never-ending loop
 
Join Date: Jun 2022
Posts: 9
valentinator is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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?
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.
Reply With Quote
  #4  
Old 06-10-2022, 12:35 AM
Guessed's Avatar
Guessed Guessed is offline Never-ending loop Windows 10 Never-ending loop Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #5  
Old 06-10-2022, 05:47 AM
valentinator valentinator is offline Never-ending loop Windows 10 Never-ending loop Office 2019
Novice
Never-ending loop
 
Join Date: Jun 2022
Posts: 9
valentinator is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 06-13-2022, 08:48 PM
Guessed's Avatar
Guessed Guessed is offline Never-ending loop Windows 10 Never-ending loop Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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

Tags
loop, macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Never-ending loop Number series ending 50 and 100 Marcia Excel 4 08-11-2021 02:36 PM
Never-ending loop Trying to count the number of cells ending with 001 or 002 mgroessl Excel Programming 5 08-06-2019 03:39 PM
Never-ending loop how do you formulate the date by pay period ending? crussell Excel 8 02-23-2016 07:38 AM
Never-ending loop 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:40 PM.


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