+ Reply to Thread
Results 1 to 17 of 17

Extracting data from Word document to populate Excel spreadsheet

  1. #1
    Registered User
    Join Date
    04-11-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    11

    Extracting data from Word document to populate Excel spreadsheet

    Hello,

    I am sent files in the following format (the real ones are much longer).

    Source file.

    Some of the information needs to be extracted and placed under the headings in the following Excel spreadsheet.

    To clarify, all of the text from the text box below 'Work' should go in the work column (in one cell) and the same goes for 'Sample reply'.

    The actual docs occasionally have pictures in the 'Work' text box, these can be omitted. The formatting i.e. text boxes within the Work' text box can be ignored but the line breaks are useful.

    I am after a macro, or some steps which will make this a more efficient process. A friend of mine had a go at doing this using Mat-lab but couldn't manage it completely as the information is "too irregular". I am completely lost and am not good enough to write a Macro for this (if one exists), but I will be able to edit one based on these docs.

    I would appreciate any help on this, please let me know if the question information is unclear and I will re-clarify.
    Thanks in advance to everyone who has a go!

    J

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Extracting data from Word document to populate Excel spreadsheet

    Having nested tables, possibly with varying numbers of internal tables, makes what you're proposing to do unnecessarily complicated. Is there a reason you must have nested tables? That said, try something based on:
    Please Login or Register  to view this content.
    The macro has its own file browser, so it will automatically process all documents in the selected folder.
    Last edited by macropod; 05-17-2013 at 10:55 AM. Reason: Minor coding error
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    04-11-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Extracting data from Word document to populate Excel spreadsheet

    Hi Paul,

    Thanks for your help, however you will need to slow it down for me a great deal, as I do not follow the above at all.

    Firstly, nested tables? I wasn't aware I was asking for this. Does this mean the text boxes and pictures within text boxes?
    Secondly, do you have any instructions as to how I run the Macro above?

    I was banking on a very similar macro to the one I will eventually need, my changes would be minor and superficial once I have it. I am a complete novice.

    Many thanks and apologies!

    J

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Extracting data from Word document to populate Excel spreadsheet

    The document in your link appears to have nested tables (ie one table inside another) for the 'Work' and 'Sample Reply'.

    The code goes into your Excel workbook. For macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm. Although these are for Word, the principles for Excel are the same.

    As for:
    I was banking on a very similar macro to the one I will eventually need
    That's a tall order given the sparseness of the information you've given. I suggest you install the macro and run it, then post back if you have any issues with it.

  5. #5
    Registered User
    Join Date
    04-11-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Extracting data from Word document to populate Excel spreadsheet

    Hey,

    Thanks, that makes more sense. The documents we receive are in this format there is not much I can do about that, but I will investigate. Also, I am aware that sometimes ignorance can come across as presumption, I don't really know anything so I am not aware if what I am asking is easy or hard and am very grateful for your input.

    I have run the macro but my initial error message is:

    Compile error: User-defined type not defined

    Any advice?

    Thanks,

    J

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Extracting data from Word document to populate Excel spreadsheet

    You'll see a comment at the top of the code about a reference to the Word object model being required. That's because the code uses what is called 'early binding'. To add the required reference, open your Excel file, open the Excel vbe (Alt-F11), select your file from the left panel, then Tools|References and, from the dropdown scroll down till you see "Microsoft Word # Object Library" and select it.

  7. #7
    Registered User
    Join Date
    04-11-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Extracting data from Word document to populate Excel spreadsheet

    Cheers, this worked.

    Now it lets me select the folder after it has run for maybe two or three seconds, I then selected the folder containing the word doc, and then nothing happens, no message or anything, it just stops. Do you know why this is?

    Many thanks,

    J

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Extracting data from Word document to populate Excel spreadsheet

    Did you look in the worksheet? Does the folder have documents of the kind displayed in your link? Do those documents have data in the cells to populate the worksheet with?

  9. #9
    Registered User
    Join Date
    04-11-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Extracting data from Word document to populate Excel spreadsheet

    At the moment the folder has one word document in which is the trial one I have on Google docs. Nothing ended up on the Excel sheet though. Do I need to have the word doc open?

  10. #10
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Extracting data from Word document to populate Excel spreadsheet

    Because I had to copy & paste your GoogleDoc from your link into Word, it's possible the structure changed somewhat in the transition. That wouldn't have been an issue had you attached it to a post here, which you can do via the paperclip symbol on the 'Go Advanced' tab. If you can do that, I'll take another look at it - the code certainly works fine with the converted copy.

  11. #11
    Registered User
    Join Date
    04-11-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Extracting data from Word document to populate Excel spreadsheet

    Pretesting Items.docx

    I think I just attached it. Here you go.

    Thanks again for your continued effort.

  12. #12
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Extracting data from Word document to populate Excel spreadsheet

    OK, the issue was just a trivial 'left-over' from my testing. In the macro in your workbook, you'll find the line:
    strFile = Dir(strFolder & "G*.doc", vbNormal)
    Change this to:
    strFile = Dir(strFolder & "*.doc", vbNormal)

  13. #13
    Registered User
    Join Date
    04-11-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Extracting data from Word document to populate Excel spreadsheet

    Hi,

    It is sort of working now. It does the first three but then failed to import 'Paul McCartneys' details. Did it successfully do all four for you?

    I have spoken to a superior and we may be able to get the document tidied up, which will get rid of the nested tables problem. Hopefully then it will work successfully.

    Thanks for your support!

    J

  14. #14
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Extracting data from Word document to populate Excel spreadsheet

    The macro ran fine for me with your 'Pretesting Items.docx'.

  15. #15
    Registered User
    Join Date
    03-14-2017
    Location
    Toronto, Canada
    MS-Off Ver
    13
    Posts
    3

    Re: Extracting data from Word document to populate Excel spreadsheet

    Hello Paul,

    I've been searching for a solution, very similar to this. I am new to VB but have used your code and the test file successfully. I have created a second document and see that everything from the folder pulls into the Excel sheet.

    This is amazing Paul, thanks for sharing.

    What I need goes a step beyond, and I'm hoping you can help me with this.

    My Word doc is a form with information such as Model and Serial Number. I need to have the information placed in certain columns on the excel spreadsheet as I'm adding it to an existing inventory spreadsheet which cannot be changed and has many more columns of information than I collect in my Word form.

    I can make my form a table, with the same heading names as the columns in Excel if there is a benefit to do so.

    Is there a way to take the info in the first field (Name), currently placed in Column A when the macro runs and direct it to Column C for example?

    If I know how to do that I could modify the code accordingly.

    Many thanks for your time and support!

    (Sorry for duplicate post - my first time in a forum)
    Last edited by achieve1; 03-14-2017 at 08:01 PM.

  16. #16
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Extracting data from Word document to populate Excel spreadsheet

    Yes, that could be done. You should start a new thread clearly setting out your requirements. This should include details about where the Model and Serial Number can be found and what other details - and from where - you need to extract.

  17. #17
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Extracting data from Word document to populate Excel spreadsheet


+ 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