+ Reply to Thread
Results 1 to 12 of 12

Copying Highlighted Text from a number of word documents to excel sheet macro

  1. #1
    Registered User
    Join Date
    01-21-2015
    Location
    California
    MS-Off Ver
    2013
    Posts
    7

    Copying Highlighted Text from a number of word documents to excel sheet macro

    Hello all,

    I am only versed in the basics of excel and need a macro to organize some data. Any help anyone could provide would be greatly appreciated or let me know if this is possible. I have a number of word documents containing DNA sequencing data, each word document has two highlighted regions of interest, highlighted in two separate colors. I need to consolidate these sequences into an excel sheet, where each row corresponds to a different set of sequence data and two columns that contain the two region of interests. I need a macro that could open a series of word documents with the same name as they appear on the excel sheet and copy the two highlighted sequences and paste it into the appropriate columns of excel. I have attached a example picture of how sheet needs to be set up. I would prefer to avoid having to go into each word document if possible as there are hundreds. Please let me know if this is possible. Any help you could provide would be greatly appreciated.
    capture example.JPG
    Thanks

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    It took a few hours, but I was able to piece it all together. It's a third of one sub, a third of another, and rest of the stitches are from me.

    While the first codey bits use Late Binding, I didn't at the end so you'll need to enable referencing to MS Word 14.0 Object Library.
    (VB Editor->Tools->References)


    Please Login or Register  to view this content.
    Last edited by daffodil11; 01-21-2015 at 09:07 PM.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    01-21-2015
    Location
    California
    MS-Off Ver
    2013
    Posts
    7

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    Thanks for your help! I will give this a try ASAP and let you know how it worked out. Thanks again!

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    No problem, glad I could help out. I enjoy exploring the realm of what-if. This was all new for me.

  5. #5
    Registered User
    Join Date
    01-21-2015
    Location
    California
    MS-Off Ver
    2013
    Posts
    7

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    Hi daffodil11,

    I tried out the macro you posted, unfortunately I get an error when I try to run it. Debugging mode showed the problem was with the line:

    '~~> Establish an Word application object
    Set oWordApp = GetObject(, "Word.Application")

    Was there a change I needed to make with this line? Thanks again for your help

  6. #6
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    Checklist

    1.) The big one: did you enable referencing to MS Word 14.0 Obj Library?
    2.) Did you change filepath in code?

    Please Login or Register  to view this content.
    Last edited by daffodil11; 01-22-2015 at 04:39 PM.

  7. #7
    Registered User
    Join Date
    01-21-2015
    Location
    California
    MS-Off Ver
    2013
    Posts
    7

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    Hi Daffodil,

    Sorry for the late reply and thanks for the continued help. I ensured that Microsoft word object library was enabled and that I changed the file path (Mine say 15.0 rather than 14.0 not sure if that matters). However, I still am getting the "Run-time error '429' ActiveX component can't create object" and debug still highlights the same line. Attached is a screen grab of references enabled, please let me know if you see anything problematic. capture example 3.JPGcapture example 2.JPG

    Thanks
    Attached Images Attached Images

  8. #8
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    It works just fine on my end. I ran it through 2 word docs and pulled the yellow and gray.

    I did a little research and found this:


    Please Login or Register  to view this content.
    Try inserting those two extra lines and let me know.


    Essentially, the code may fail if Word isn't running somewhere yet. So this creates an instance to run in the background the first time, and then skips it every other time.
    Last edited by daffodil11; 01-23-2015 at 05:17 PM.

  9. #9
    Registered User
    Join Date
    01-21-2015
    Location
    California
    MS-Off Ver
    2013
    Posts
    7

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    Thanks!!! Those two lines of code seemed to have fixed it and now it is working. However, the second set of sequences (those highlighted in grey) become offset and don't copy to the appropriate row. As show in the screen grab. If you know of way to fix this, that would be much appreciated, but if not, that's alright. It would not be too much trouble to cut and shift the entire column up. Thanks again for all you help you have saved me a lot of time. Thank you!! capture example 4.JPG

  10. #10
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    That means it detected something in C11. The code for the PasteTo auto-detects the first empty cells in B and C starting from the bottom.

    Perhaps there was just an single space floating in C11?



    To prevent this, you can set a clear command at the beginning of the macro (right after the Dim statements) to kill B2:C200 or something.

    Please Login or Register  to view this content.

    Thank you for suggesting this interesting puzzle. This solve was the very first time I've attempted cross-application coding, and the results were well worth the time put in to achieve them.

  11. #11
    Registered User
    Join Date
    01-21-2015
    Location
    California
    MS-Off Ver
    2013
    Posts
    7

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    Hi daffodil11,

    Thanks again for all your help. I was wondering if you could provide a solution to one more issue. In the excel sheet, there are some rows with clones that have not yet been sequenced and therefore have no word document equivalent with it's sequence data in the folder in which the macro is pulling the information from. This seems to cause an issue with the macro and it runs into an error when it cannot locate these files. Do you know if there is a line of code similar to the "On error resume next" code used earlier that will allow the macro to fill in the sequence data for those rows that have word docs in the folder but skip or ignore those that do not? Thanks again, and if this proves too complicated I can always just run the macro after every clone's sequence has been analyzed.

    Thanks!

  12. #12
    Registered User
    Join Date
    01-21-2015
    Location
    California
    MS-Off Ver
    2013
    Posts
    7

    Re: Copying Highlighted Text from a number of word documents to excel sheet macro

    The macro appears to be successfully pulling data from the word documents now. however, it does not seem to be copying them to the correspond row. Instead just going in order whether or not the sequence data exists for that clone. For example, sequence data is complete for clone 1 and 3, but the macro fills the data for clone 1 and 2 which has no corresponding word document. Please let me know if you have any ideas of how to get it to fill in the corresponding row rather than just filling in the rows in order. Thanks again for any help you can provide, I really appreciate it!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to get this and 250+ similar Word documents in one excel sheet
    By waavn in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 09-28-2014, 01:26 PM
  2. Macro to check data from Word documents against an excel spread sheet
    By xxgirlinbluexx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-20-2013, 01:25 PM
  3. VBA Code to create n number of word documents from excel range.
    By skonduru in forum Word Formatting & General
    Replies: 1
    Last Post: 01-30-2013, 03:04 AM
  4. Replies: 0
    Last Post: 09-01-2010, 04:56 PM
  5. Issues copying excel charts to word documents - using Excel VBA
    By Frankie in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-20-2006, 10:40 AM

Tags for this Thread

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