Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2024, 09:44 AM
Italophile Italophile is offline Puzzling Behavior Windows 11 Puzzling Behavior Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Find doesn't work simply because you are attempting to execute multiple find operations within a looped find.



Instead try the following:

Code:
Sub PrepDocument()
    '
    ' Temporarily rename "5AX"
    '
    '
    With ActiveDocument.Content.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Text = "5AX TRIM"
        .Replacement.Text = "BAD TRIM"
        .Execute Replace:=wdReplaceAll
        .Text = "-."
        .Replacement.Text = "-0."
        .Execute Replace:=wdReplaceAll
        .Text = "X."
        .Replacement.Text = "X0."
        .Execute Replace:=wdReplaceAll
        .Text = "Y."
        .Replacement.Text = "Y0."
        .Execute Replace:=wdReplaceAll
    End With


End Sub

Sub SwitchXAndY()

    Dim findRange As Range: Set findRange = ActiveDocument.Content
    Dim switchText() As String

    On Error Resume Next

    ' Go to the string "X*Y"
    With findRange
        With .Find
            .ClearFormatting
            .Forward = True
            .MatchWildcards = True
            .Wrap = wdFindStop
            .Text = "X*Z"
        End With
        Do While .Find.Execute = True
            .MoveEnd wdCharacter, -2
            switchText = Split(.Text, " ")
            .Text = switchText(1) & " " & switchText(0)
            .Collapse wdCollapseEnd
        Loop
    End With
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Puzzling behavior by Window shape in [Walls, Shell and Structure] csdlman Visio 3 06-12-2018 03:50 AM
Puzzling Read Only Issue BertLady PowerPoint 0 10-15-2014 11:40 AM
Odd cursor behavior markg2 Outlook 0 06-15-2010 08:33 AM
Bizarre behavior Mozydan Outlook 0 11-19-2007 08:59 AM
Odd Behavior from Outlook stonkers Outlook 0 03-14-2006 12:50 PM

Other Forums: Access Forums

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