#1
|
|||
|
|||
Counting the number of changes a macro makes
Hi fellas,
I'm very sorry to bother you again. I've spent quite a few hours trying to figure this out, but even the simple things are complicated when you're a complete novice. I've tried using the "Dim iCount As Integer" and adding various While/Wends and If/Elses etc in various parts of the macro with the message box at the end to tell me how many changes have been made but I can't get it to work. Here's a macro to delete the red footnote numbers (and a space after them) from the main text. I've also tried different kinds of execution such as "wdReplaceOne" and putting a simple execute on a loop, but I won't clutter things up by posting numerous failed codes here. I suspect "ReplaceAll" won't be compatible with a counter (but I could be wrong about that too). Could one of you alter this macro so that it counts the changes. Then I should be able to use that as a guide/template for any other macros. Thanks once again for your help, and I wouldn't be asking If I hadn't already put considerable effort into figuring it out myself. Sub DeleteFootnoteNumbers() Selection.Find.Font.Color = wdColorRed Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^2 " .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True Selection.Find.Execute Replace:=wdReplaceAll End With End Sub |
#2
|
||||
|
||||
Try
Code:
Sub DeleteFootnoteNumbers() Dim x As Long With Selection.Find .ClearFormatting .Font.Color = wdColorRed .Replacement.ClearFormatting .Text = "^2 " .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True Do While .Execute(Replace:=wdReplaceOne) x = x + 1 Loop End With MsgBox "Replaced: " & x End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
That works perfectly of course Andrew. Thank you.
I nearly had it, but when it comes to codes, 'nearly' is useless. And thanks for replying so quickly. |
#4
|
|||
|
|||
I’m embarrassed that I have another problem so soon, and after this I promise that I won’t ask any more questions for at a least a month. I have 1000s of other things to do and I’m sure you do too. My notion of using your solution as a template for other macros has failed miserably.
The first part of the following macro is the code you gave me yesterday. It deletes the red footnote numbers. My idea was to copy and paste the “Do While” loop onto the end of the second part after removing the “Selection.Find.Execute Replace:=wdReplaceAll” line. Evidently my plan wasn’t fool-proof. At the minute the code works great – it cleans up the red footnotes that have been moved into the text. It deletes the footnote numbers and then changes the size and colour of the footnotes (which are now in the text) to match the size and colour of the surrounding text. But when I try to add the loop to the end of the second part (which is also the end of the macro) so that I can count the changes, it won’t loop, it only makes one change and then stops. Sub CleanupMovedFootnotes() ' Delete Red in-text footnote numbers Dim x As Long With Selection.Find .ClearFormatting .Font.Color = wdColorRed .Replacement.ClearFormatting .Text = "^2 " .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True Do While .Execute(Replace:=wdReplaceOne) x = x + 1 Loop End With ' Change in-text Red Size 9 To Black Size 10 With Selection.Find.Font .Size = 9 .Color = wdColorRed End With With Selection.Find.Replacement.Font .Size = 10 .Color = wdColorAutomatic End With With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll MsgBox "Replaced: " & x End Sub |
#5
|
|||
|
|||
Here's a test sample for you to try it on, if that helps. [edited to remove attachment at request of poster]
Last edited by Charles Kenyon; 11-10-2020 at 02:07 PM. Reason: remove attachment at request of poster |
#6
|
||||
|
||||
John_4
Go back to the other thread. Change the line RngTgt.FormattedText = RngSrc.FormattedText to RngTgt.Text = RngSrc.Text That macro does everything you asked for here except return a count of the move/deletions. You can figure out how to get the count by taking the relevant lines from here.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
You're right Andrew, it does. You're a genius
As per my promise I'll now take a holiday from imposing upon you. However i do have one last question I thought you might be able to easily answer... Initially when I ran the macro it left a white square in the text where the footnote number had been. I had been looking online and in the symbols section of Word trying to find the square's character code so i could delete it. It took me about 1 and 1/2 hours to realise that it was caused by having a space before the footnote number in the footnotes range. When I deleted the space and then ran the macro all was good. Any idea what that square is, or if it has a code in case we meet again? It didn't match any code I could find. I've attached a sample with the squares in it. Regardless of the answer to that, thank you once again for your very generous help. Last edited by Charles Kenyon; 11-10-2020 at 02:08 PM. Reason: remove attachment at request of poster |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
need help in counting the number of rows that contain 5 consecutive X | Marcia | Excel | 10 | 11-25-2018 08:41 PM |
Counting rows with a macro? | Jennifer Murphy | Word Tables | 1 | 08-23-2016 03:00 PM |
Counting the number of opening of a document | sannhei | Word | 2 | 03-27-2015 05:40 AM |
Counting unique visitors by ward, counting monthly visits by status, editing existing workbook | JaxV | Excel | 9 | 11-14-2014 12:25 AM |
Counting Number of Months from a static date | bremen22 | Excel | 4 | 11-25-2013 11:57 AM |