+ Reply to Thread
Results 1 to 14 of 14

Copying data out of a word document issue

  1. #1
    Registered User
    Join Date
    10-22-2014
    Location
    Hyde, Manchester
    MS-Off Ver
    2010
    Posts
    79

    Copying data out of a word document issue

    Good afternoon all,

    I am trying to run a macro to loop through all the tables in a word document and take the values that are below the title and copy them into excel. I believe that I have most of the code in place but when I run it I get a "Type mismatch error" for the document that I am trying to open.

    The variable "testlist" is a file path that has been generated by the previous sub and that variable is stored as a "Variant" (although it still doesn't work when I store it as a "String")

    My code is below and any help is greatly appreciated!


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Copying data out of a word document issue

    From reading, there's nothing wrong with the code so the questions are:
    • What is the scope of 'testlist'
    • If it is in scope for this procedure, what does it contain?
    • If it contains a file name, does that file actually exist?

  3. #3
    Registered User
    Join Date
    10-22-2014
    Location
    Hyde, Manchester
    MS-Off Ver
    2010
    Posts
    79

    Re: Copying data out of a word document issue

    Hi mate,

    testlist is defined like this:

    Please Login or Register  to view this content.
    and the file path is generated by selecting the file from a dialogue box using this code:

    Please Login or Register  to view this content.
    So I know that testlist contains the correct value and that the file exists, I'm totally baffled........

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Copying data out of a word document issue

    It'd be good to know the actual value.

    For example, does it contain a fully qualified path? Can't remember what the File dialog returns offhand (Android tablet) but I'm fairly certain there's no issue with the code itself.

  5. #5
    Registered User
    Join Date
    10-22-2014
    Location
    Hyde, Manchester
    MS-Off Ver
    2010
    Posts
    79

    Re: Copying data out of a word document issue

    This is the path that is generated from the MsgBox above:

    Untitled.png

  6. #6
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Copying data out of a word document issue

    Sorry, I can't raise the Type Mismatch error when opening a document (Tested) - but it does error with err number 451 on the line
    Please Login or Register  to view this content.
    (Yes, I did add a couple of populated tables to the document).

  7. #7
    Registered User
    Join Date
    10-22-2014
    Location
    Hyde, Manchester
    MS-Off Ver
    2010
    Posts
    79

    Re: Copying data out of a word document issue

    I'm not surprised that line doesn't work (I hadn't got as far as that so that was just a guess).

    I don't understand why ours work differently? Did you declare your variable on your sheet or in a module?

  8. #8
    Registered User
    Join Date
    10-22-2014
    Location
    Hyde, Manchester
    MS-Off Ver
    2010
    Posts
    79

    Re: Copying data out of a word document issue

    I've now moved my code onto the sheet that it will be affecting (it was in a module before) and I don't get the type mismatch error any more (strangely)

    However I now get an error that says "Property let procedure not defined and property get procedure did not return an object"

    Is that a step forward or a step back I can't quite tell?

  9. #9
    Registered User
    Join Date
    10-22-2014
    Location
    Hyde, Manchester
    MS-Off Ver
    2010
    Posts
    79

    Re: Copying data out of a word document issue

    Sorry, I've just googled that error and that is error 451 but mine didn't specify a line?

  10. #10
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Copying data out of a word document issue

    step forward or a step back I can't quite tell
    Neither - in step, at least.

    I put the code in a module.

    I don't understand what you are trying to do with the table - it seems like you want to copy from row 4 to the end. General Word VBA code, not necessarily working, would be
    Please Login or Register  to view this content.
    (Just noticed I use rng as a Word range, you use a variable with the same name as an Excel range. Different things, make allowances).

  11. #11
    Registered User
    Join Date
    10-22-2014
    Location
    Hyde, Manchester
    MS-Off Ver
    2010
    Posts
    79

    Re: Copying data out of a word document issue

    OK I see what you are getting at, I've tried to implement that but I get an error for
    Please Login or Register  to view this content.
    to say "Argument not optional"? Do I have to use word vba code when searching a word document rather than excel vba code?

    Other than that it all seems to be hunky dory, I still don't understand why my code works on the sheet but didn't work in a module...... Very strange
    Last edited by tom.mat.walker; 06-17-2016 at 06:23 AM.

  12. #12
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Copying data out of a word document issue

    This, whether in a standard module or Sheet class module, works fine.
    Please Login or Register  to view this content.
    I mean 'fine' as in it does not error, however there is a logic error in that you loop through all the tables in the Word document and paste to the same range on the Excel sheet. There may only be 1 table, I don't know... but that is something I would certainly pick up on if that code was submitted to me.

  13. #13
    Registered User
    Join Date
    10-22-2014
    Location
    Hyde, Manchester
    MS-Off Ver
    2010
    Posts
    79

    Re: Copying data out of a word document issue

    Hi mate thanks for all your help that has absolutely nailed it, I know there is a logic error later on but I thought I would get it working and then sort all the offsets out once I've got that working!

    Thanks again

    Tom

  14. #14
    Registered User
    Join Date
    10-22-2014
    Location
    Hyde, Manchester
    MS-Off Ver
    2010
    Posts
    79

    Re: Copying data out of a word document issue

    One final question, I have been going through some of the docs that will be affected and some of them have vertically merged cells as their first column. This seems to cause problems with this code. Any way you can think of to get round this?

    Thanks

    Tom

+ 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] Copying listbox entries to Word document
    By AndyE in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2015, 02:12 PM
  2. VBA will randomly break while copying data to word document.
    By chaddug in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-04-2014, 02:34 PM
  3. [SOLVED] Mail Merge issue when using VBA to go from Word document to PDF
    By Max_Taylor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-31-2012, 02:53 PM
  4. Copying text box content into a word document
    By loud_scream in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2012, 10:18 AM
  5. copying from excel to word document
    By walid66 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-02-2007, 01:36 PM
  6. Copying Cell data and pasting into word document?
    By Simon Lloyd in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-07-2006, 05:41 AM
  7. [SOLVED] Copying an Excel chart into a Word document
    By Carolyn in forum Excel General
    Replies: 7
    Last Post: 07-11-2005, 03:05 PM

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