Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2025, 05:15 PM
batman1 batman1 is offline Help, How to have only a selected text to change = Range Windows 11 Help, How to have only a selected text to change = Range Office 2013
Advanced Beginner
 
Join Date: Jan 2025
Posts: 57
batman1 is on a distinguished road
Default

As far as I understand what this is about
Code:
Sub demo()
Dim oRng As Range, months, k As Long
    If Selection.End = Selection.Start Then Exit Sub
    
    Application.ScreenUpdating = False
   
    Set oRng = Selection.Range
    
    With oRng
        Selection.LanguageID = wdFrenchCanadian
        Selection.NoProofing = False
    End With
    Application.CheckLanguage = True
    
    months = Array(Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), _
    Array("janv.", "févr.", "mars", "avr.", "mai", "juin", "juill.", "aout", "sept.", "oct.", "nov.", "déc."))

    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Font.Color = 16711937                             'Blue HTML 1/1/255
        .MatchCase = True
        .MatchWildcards = True
        .Text = "([A-Z][a-z]{2}) ([0-9]{1;2}), ([0-9]{2})"
        .Replacement.Text = "\2 \1 20\3"
        .Execute Replace:=wdReplaceAll
        oRng.Expand wdWord
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Font.Color = 16711937
        .MatchCase = True
        .MatchWildcards = False
        For k = 0 To 11
            .Text = months(0)(k)
            .Replacement.Text = months(1)(k)
            .Execute Replace:=wdReplaceAll
        Next k
    End With
    Application.ScreenUpdating = True
End Sub

Reply With Quote
  #2  
Old 01-26-2025, 06:26 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help, How to have only a selected text to change = Range Windows 10 Help, How to have only a selected text to change = Range Office 2019
Competent Performer
Help, How to have only a selected text to change = Range
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 200
Cendrinne is on a distinguished road
Red face Ohhhhhh with a few stuff I needed to add on my side, IT WORKS

OMG, all afternoon, it kept trying and trying.

The only thing I thought of doing, was to put a font color and if it is that exact font color then do the Find and Replace.

However, I left your script in black or automatic and it WORKS!!!!!!

Thank you so much. This helps me so much.

I can't thank you enough
Reply With Quote
Reply

Tags
help me, range, selection



Similar Threads
Thread Thread Starter Forum Replies Last Post
Count lines within selected text range eduzs Word VBA 4 09-17-2023 05:22 PM
Change background of selected text ultrarunner2020 Word 5 03-10-2023 02:59 PM
Applying a VBA code only on a selected text or range RobertDany Word VBA 2 10-09-2021 08:31 AM
How to change color indicating selected text daylee Word 1 03-27-2019 01:31 PM
Please help. I want to change the text of a cell when another is selected frankzelnik Excel 5 06-19-2018 01:34 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:58 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