-
May 2nd, 2022, 09:47 AM
#1
Thread Starter
New Member
New to VBA and need help!
Hey everyone, I'm new to VBA and want to write a script that would search a word document for a list of acronyms and replace the first instance of the acronym with the spelled out version. My thoughts is that I would need to create a two column array, one with the acronym and the other column with the definition. Then some sort of a loop or "Find and Replace" to go through the document looking for each of the acronyms listed in column one of the array.
Any help on the approach and the actual coding would be helpful! I've never written a script on VBA before and it's hard to understand how to get it to work.
Thanks!
-
May 2nd, 2022, 01:47 PM
#2
Re: New to VBA and need help!
Possibly useful links to get you started:
https://gregmaxey.com/word_tip_pages..._document.html
https://docs.microsoft.com/en-us/off...-or-formatting
https://wordmvp.com/FAQs/MacrosVBA/F...AllWithVBA.htm
Note that you would need to replace only the first instance of each Acronym on your list.
An enhanced version of the macro could also use an Excel workbook sheet to contain the list of acronyms and their replacements, which would enable the acronym list to be updated more easily and by users with no knowledge of VBA.
-
May 2nd, 2022, 03:00 PM
#3
Re: New to VBA and need help!
something else to potentially be considerate of... Let's say you have an acronym that's "ABC" ... and it appears 6 times. You run it oince, and it changes the first ABC to A Better Control, there are now 5 occurences of the acronym. Now, someone edits the document, and you want to re-run the tool to make sure you "fix" any that may have been added. It';s going to skip "A Better Control" and find the first "ABC" ... which used to be the second one ... and replace that. Now you have "A Better Control" twice and "ABC" four times ... Just somehting to keep in mind.
-tg
-
May 3rd, 2022, 01:34 AM
#4
Re: New to VBA and need help!
to add to jdc and tg:
What you're describing is a "Dictionary" *hint hint*
Something else: Should your script only replace "full" occurences or also "partial" occurences?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
May 3rd, 2022, 05:47 AM
#5
Re: New to VBA and need help!
possibly words built in autotext may be able to do what you want
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|