+ Reply to Thread
Results 1 to 2 of 2

Loop through Excel file to replace wording in Word (VBA in excel)

  1. #1
    Registered User
    Join Date
    06-12-2013
    Location
    USA
    MS-Off Ver
    excel 2007
    Posts
    9

    Loop through Excel file to replace wording in Word (VBA in excel)

    I am trying to replace wording in a word file using an excel file. Based on if a user selects yes or no to a question, there will either be a few pages of wording or no wording at all. What I have done is set up placeholders in the word file (%placeholder1%, %placeholder2%, etc) and if the user answers no, the placeholders are replaced by "". If the user selects yes, %placeholder1% is replaced by cell A1, %placeholder% by cell A2, etc.

    I got the loop macro to work when I was bringing up the file and saving it all in that one macro, but I need to do this for several questions in the same file. So I need to have the test macro call a few loop macros. Not sure how to get it working with opening the word file in the main macro instead of the loop one. Here is my code:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I am running into a problem in the test macro here: Worksheets("EngineeringFee").Range("A1").Select

    EDIT: The error is "select method of Range class failed"

    In the test macro, I am going to need to be able to call loop, loop2(another macro), loop3, etc. Therefore I think I need to set the active cell each time to where it needs to be for the loop macro as that is how I iterate through cells. I'm not sure if I need to change how I iterate through. I plan on making a search macro to cut down on code length, and I'm sure there are other ways I could make the code more efficient but I just need the damn thing to work!

    Any help would be greatly appreciated.
    Last edited by frongi; 06-13-2013 at 11:22 AM.

  2. #2
    Registered User
    Join Date
    06-12-2013
    Location
    USA
    MS-Off Ver
    excel 2007
    Posts
    9

    Re: Loop through Excel file to replace wording in Word (VBA in excel)

    Well I got it to work. Just had to select the sheets and the cells separately. Hopefully this helps someone out in

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1