none
How can I use VB to find and replace multiple blocks of text? RRS feed

  • Question

  • Good morning all, I am literally brand new to coding, so I apologize if there's an easy answer that I just couldn't find.

    At work we have a few template documents that need constant editing. The current solution is we have highlighted a block of words ("phone number" , "contact name" etc.) and we would copy the highlighted text, use the find and replace tool to insert whatever information needs to be input throughout the document.

    It's ugly, but it works. It also takes a long time. I was hoping I could create some sort of script that as soon as I open the document, a message box would come up and say "Phone number?" and let me input the phone number in a dialog box of some sort under it. Then "contact name?" and let me put the name in the box under that, etc. And when I hit submit or okay, it would go through the document and replace all of the text that needs to be edited with what I input through the dialog box.

    I would like to try and figure this out or code it myself, but like I said, this is all pretty much greek to me.

    Is there a resource somewhere or a tutorial of some sort that I can find to help me with this?

    Thanks everyone for your time

    Tuesday, April 2, 2013 5:27 PM

All replies

  • Good morning all, I am literally brand new to coding, so I apologize if there's an easy answer that I just couldn't find.

    At work we have a few template documents that need constant editing. The current solution is we have highlighted a block of words ("phone number" , "contact name" etc.) and we would copy the highlighted text, use the find and replace tool to insert whatever information needs to be input throughout the document.

    It's ugly, but it works. It also takes a long time. I was hoping I could create some sort of script that as soon as I open the document, a message box would come up and say "Phone number?" and let me input the phone number in a dialog box of some sort under it. Then "contact name?" and let me put the name in the box under that, etc. And when I hit submit or okay, it would go through the document and replace all of the text that needs to be edited with what I input through the dialog box.

    I would like to try and figure this out or code it myself, but like I said, this is all pretty much greek to me.

    Is there a resource somewhere or a tutorial of some sort that I can find to help me with this?

    Thanks everyone for your time

    Tuesday, April 2, 2013 4:27 PM
  • Hello,

    If you are using MS-Word documents check out the forum below

    http://social.msdn.microsoft.com/Forums/en-US/worddev/threads


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Tuesday, April 2, 2013 4:59 PM

  • Stefan Blom, Microsoft Word MVP
    Tuesday, April 2, 2013 6:19 PM
  • I agree with Kevin that if these are MS Word documents then the functionality you seek is already built into Word.

    If they are plain text files, you could do this easily in VB with a simple data entry form and a small modification to your template files allowing them to work with the String.Format method.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, April 2, 2013 6:58 PM