Results 1 to 5 of 5

Thread: New to VBA and need help!

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    1

    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!

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    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.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    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

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
  •  



Click Here to Expand Forum to Full Width