Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 02-20-2025, 03:01 AM
Ddadoo57 Ddadoo57 is offline problem with capturing group in findText/ReplaceWith Windows 11 problem with capturing group in findText/ReplaceWith Office 2021
Advanced Beginner
problem with capturing group in findText/ReplaceWith
 
Join Date: Feb 2023
Posts: 90
Ddadoo57 is on a distinguished road
Default

if I set


Code:
objDoc.TrackRevisions = true
the replacement with your code gives HiHello… !



my code also works with objDoc.TrackRevisions = false
Code:
texte.Find.ClearFormatting
texte.Find.Replacement.ClearFormatting
texte.Find.MatchWildcards = True
texte.Find.Execute FindText:="…([A-Za-zÀ-ÖØ-öø-ÿ0-9])", ReplaceWith:="… \1", Replace:=wdReplaceAll
and if I set objDoc.TrackRevisions = true, the only code I found was the code I mentioned earlier, namely :
Code:
    With texte 'pour "…[A-Z]"
        With .Find
            .Forward = True: .Wrap = wdFindStop: .MatchWildcards = True
            .Text = "…[A-Za-zÀ-ÖØ-öø-ÿ0-9]"
        End With
        Do While .Find.Execute = True
            .Text = "… " & Right(.Text, 1): .Collapse wdCollapseEnd
        Loop
    End With
Reply With Quote
  #17  
Old 02-20-2025, 03:31 AM
macropod's Avatar
macropod macropod is online now problem with capturing group in findText/ReplaceWith Windows 10 problem with capturing group in findText/ReplaceWith Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,465
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

You could, of course, use Word's built-in document compare feature without using track changes while running your code. The built-in document compare feature will generate a result equivalent to a document with track changes.

Alternatively, you would use something like:
Code:
Sub Demo()
Application.ScreenUpdating = False
ActiveDocument.TrackRevisions = True
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWildcards = True
    .Text = "…[A-Za-zÀ-ÖØ-öø-ÿ0-9]"
    .Wrap = wdFindStop
    .Forward = True
  End With
  Do While .Find.Execute
    .Characters.First.InsertAfter " "
    .Collapse wdCollapseEnd
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #18  
Old 02-20-2025, 04:00 AM
Ddadoo57 Ddadoo57 is offline problem with capturing group in findText/ReplaceWith Windows 11 problem with capturing group in findText/ReplaceWith Office 2021
Advanced Beginner
problem with capturing group in findText/ReplaceWith
 
Join Date: Feb 2023
Posts: 90
Ddadoo57 is on a distinguished road
Default

Thank you, it works very well (it's a bit like what I was proposing), but I find it cleaner and I'll adopt it, thank you. With this solution I'll be able to get around the problem with group captures when TrackRevisions is true.

Have a nice day!
Reply With Quote
  #19  
Old 03-01-2025, 11:16 AM
Ddadoo57 Ddadoo57 is offline problem with capturing group in findText/ReplaceWith Windows 11 problem with capturing group in findText/ReplaceWith Office 2021
Advanced Beginner
problem with capturing group in findText/ReplaceWith
 
Join Date: Feb 2023
Posts: 90
Ddadoo57 is on a distinguished road
Default

Just to end this thread, here's the solution I've adopted:
- I no longer track modifications (.TrackRevisions = False)
- in most cases, I simply process my corrections with or without MatchWildcards.
- finally, I've created a procedure that compares the original files and those to which the punctuation correction has been applied. This creates a comparison file where the corrections are clearly highlighted.
Thanks for your contributions!

PS: I'd just like to remind you that this problem comes from an unhandled error in VBA. We can't track changes and use group captures correctly in our find/replace.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with capturing group in findText/ReplaceWith Find and Replace not capturing entire line Steve Kunkel Word VBA 7 04-22-2021 10:00 AM
problem with capturing group in findText/ReplaceWith Capturing numbered headings jbvalen Word VBA 5 05-04-2017 05:03 PM
problem with capturing group in findText/ReplaceWith Capturing Redirected URL with macro souravkp Word VBA 1 07-11-2015 09:34 PM
problem with capturing group in findText/ReplaceWith Capturing addresses into contacts lordnacho Outlook 1 11-01-2010 06:05 PM
time capturing aligahk06 Excel 0 04-18-2010 11:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:53 PM.


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