Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-16-2025, 05:21 AM
Aengus345 Aengus345 is offline Eliminating/simplifying search and replace code lines to just 2 lines each ... (???) Windows 10 Eliminating/simplifying search and replace code lines to just 2 lines each ... (???) Office 97-2003
Novice
Eliminating/simplifying search and replace code lines to just 2 lines each ... (???)
 
Join Date: Feb 2024
Posts: 8
Aengus345 is on a distinguished road
Question Eliminating/simplifying search and replace code lines to just 2 lines each ... (???)

Good morning!

I have a script I wrote about a year ago that was cumbersome to begin with but is becoming more and more unwieldly as time goes on!
I'm not very good at VBA, but I can work with rudimentary syntax if it's easy enough for me to see and figure out what is going on and what I have to do.

The simple code I found via recording keystrokes puts the structure below into my macro. I now have somewhere between 40 and 50 of these search and replace code blocks (!!!):

Code:
'----------------------------------------------
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
       .Text = "Orbis factor"
        .Replacement.Text = "Órbis fáctor"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
'----------------------------------------------
I don't even know if it's possible to simplify this in the way I'm going to describe, but I have to ask to see. It would be ideal, I think, to just have something simple where instead of each time having to add a code block for a new search and replace, that I can add just 2 lines with the target and desired code (?).

i.e., in the example above, the document I get that I need to edit is missing emphasis accents in the Latin, such as this:

Orbis factor

For clarity's sake, I need to edit to show syllable emphasis, like this:



Órbis fáctor


If at all possible, it would be easier to maintain a word list (preferably contained within the macro itself and not accessing the information from an external source -- not sure if this is procedure but in an automation language I do now how to use quite a bit better than VBA, this is a common procedure).

This type of solution with a word/phrase list would mean that I can then keep everything orderly and easy to maintain as I'd put all these words/phrases to be edited in alphabetical order (with first word/phrase being how it gets sent to me, followed by accented or diphthong corrections I need to make) ... :

ae
æ
Dicit
Dícit
Est
Ést
Nunc
Núnc
Orbis factor
Órbis fáctor
(etc., etc.)

This may not be even possible, I just don't know. All I know is that I need a structure that is as easy to work with as the simple, 1-item-per-row list above (?).

I hope that I've explained okay. If more clarification is needed, please let me know.

Thank you!

Reply With Quote
  #2  
Old 02-16-2025, 04:14 PM
macropod's Avatar
macropod macropod is offline Eliminating/simplifying search and replace code lines to just 2 lines each ... (???) Windows 10 Eliminating/simplifying search and replace code lines to just 2 lines each ... (???) 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

This has been addressed before. See, for example: https://www.msofficeforums.com/word-...ing-macro.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Eliminating/simplifying search and replace code lines to just 2 lines each ... (???) How do I copy text from wxcel and paste to word , eliminating lines but keeping columns aligned? KPS2019 Word 4 05-31-2019 04:04 PM
Eliminating/simplifying search and replace code lines to just 2 lines each ... (???) Search for lines that DO NOT have specific character knpaddac Word 1 01-14-2019 01:16 PM
Trying to add space between lines of bulleted text and a new header but both lines are moving??? Martin_d35 Word 2 02-10-2017 07:13 AM
Eliminating extra lines when pasting copied text debip58 PowerPoint 0 09-14-2015 03:22 PM
Eliminating/simplifying search and replace code lines to just 2 lines each ... (???) Eliminating blank lines in mail merge (labels) BeerStud Mail Merge 1 11-28-2014 06:29 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:42 AM.


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