+ Reply to Thread
Results 1 to 23 of 23

Copying data from Excel to Word

  1. #1
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Question Copying data from Excel to Word

    Good morning,

    I was wondering if someone could possibly assist me. I have an excel document which contains a sheet with a template I created, then I also have a word document with the same template.

    I am unsure if this is possible or not but, I would like to copy data from certain cells and paste them in the corresponding section of the word document, through a macro.

    Again I don't know if there are easier ways to do something similar to what I need, I have been trying to find something on google. I've tried to copy and paste the range onto a word document through a macro but it doesn't look right and some codes I have found, I've not been able to change them to work for my spreadsheet.

    I would appreciate any suggestions on how I could make this work, thanks.

    Gus

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copying data from Excel to Word

    Here is a suggestion. Make a sheet on your spreadsheet called "MailMerge" (or whatever makes sense to you).

    In row 1, put in meaningful headers for the data you want to put on the word document.
    In row 2 type in formulas to fill in the cells with data such as ='Sales'!$D$14

    Then use this sheet as the source for a mail merge in the word document. I might be one record long by 100 columns, but it should work.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Re: Copying data from Excel to Word

    Thank you for the reply, I will give it a go!

  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: Copying data from Excel to Word

    Quote Originally Posted by dflak View Post
    Here is a suggestion. Make a sheet on your spreadsheet called "MailMerge" (or whatever makes sense to you).

    In row 1, put in meaningful headers for the data you want to put on the word document.
    In row 2 type in formulas to fill in the cells with data such as ='Sales'!$D$14

    Then use this sheet as the source for a mail merge in the word document. I might be one record long by 100 columns, but it should work.
    No, it won't - not unless the OP wants each row on a different page, together with all of whatever exists in the document either side of the row's data. There are ways to output multiple rows to a single page via mailmerge, but this isn't it. In this case, though, it's not even evident a mailmerge is required - a DATABASE field in the Word document may suffice. For a demonstration, see: http://www.msofficeforums.com/mail-m...html#post67097
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copying data from Excel to Word

    I think that depends on the type of mailmerge you want to do: labels, document, etc. I'm doing this at work with one of our technical writers. He has a canned 100 or so page report that reads in about 150 metrics.

  6. #6
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Re: Copying data from Excel to Word

    I appreciate the replies, I came across something on google earlier about mail merge and I managed to incorporate it into my spreadsheet and word template but, it just didn't work with the word template I have as it didn't keep the structure and moved things around. I was using bookmarkers.

    Quote Originally Posted by macropod View Post
    No, it won't - not unless the OP wants each row on a different page, together with all of whatever exists in the document either side of the row's data. There are ways to output multiple rows to a single page via mailmerge, but this isn't it. In this case, though, it's not even evident a mailmerge is required - a DATABASE field in the Word document may suffice. For a demonstration, see: http://www.msofficeforums.com/mail-m...html#post67097
    Paul thank you for the reply I shall look into this when I have a bit more time later on.

    On another note, I would like to ask a quick question. I was wondering if anyone knew if I could paste special to word in HTML format through vba? I have a code that will paste what I need to word but the current code doesn't retain the look of the template on excel.

    I have tested the paste special without vba (manually) and it seems to work, but I wouldn't know how to write this into excel.

    This is the code I am using

    Please Login or Register  to view this content.
    Thank you

    Gus
    Last edited by mango2015; 03-16-2016 at 11:35 AM.

  7. #7
    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: Copying data from Excel to Word

    Quote Originally Posted by dflak View Post
    I think that depends on the type of mailmerge you want to do: labels, document, etc. I'm doing this at work with one of our technical writers. He has a canned 100 or so page report that reads in about 150 metrics.
    How about a letter with a table of the Excel data? You cannot do that with an ordinary mailmerge.

  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: Copying data from Excel to Word

    Quote Originally Posted by mango2015 View Post
    I appreciate the replies, I came across something on google earlier about mail merge and I managed to incorporate it into my spreadsheet and word template but, it just didn't work with the word template I have as it didn't keep the structure and moved things around. I was using bookmarkers.

    ....

    On another note, I would like to ask a quick question. I was wondering if anyone knew if I could paste special to word in HTML format through vba? I have a code that will paste what I need to word but the current code doesn't retain the look of the template on excel.
    Perhaps if you could explain exactly what you're trying to achieve, specific advice could be given. So far, what you've posted isn't enough to decide whether mailmerge, a DATABASE field, object linking and/or a macro might best meet your needs.

  9. #9
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Re: Copying data from Excel to Word

    Quote Originally Posted by macropod View Post
    Perhaps if you could explain exactly what you're trying to achieve, specific advice could be given. So far, what you've posted isn't enough to decide whether mailmerge, a DATABASE field, object linking and/or a macro might best meet your needs.
    Yeah no problem, I should have probably attached an example at the start.

    I have highlighted in red on the Excel document in the 'PO Template' sheet, the cells I would like to copy over to Word.

    What I am trying to do is, data would be inserted into the Excel document in the PO Template and I would then be able to press the create word doc button for example and this would then copy the data highlighted in red over to the word document template to the corresponding sections.

    I have tried several things, but am just not experienced enough to make something like this work. normal copy and paste from Excel to Word works if it's done manually, but once it's done through a macro it doesn't keep the templates structure.

    Regards

    Gus
    Attached Files Attached Files

  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: Copying data from Excel to Word

    What you could do, given that the data from Excel always originates in the same set of cells, is to copy each block of Excel cells, then paste them into Word using Paste Special with the 'Paste Link' option and whichever of the Paste Link formats best meets your needs. No code required. Simply open the Word document and there the current data will be. Presumably, though, you'll want to save a separate copy of the document for each order and not have it updating every time the Excel data change. In that case, a small amount of code will be required and, instead of saving the document as a document, you'd save it as a Word template (.dot format). In that case, all the code you might need is:
    Please Login or Register  to view this content.
    The above code would generate & save a new Word document with the Order# in the same folder as the workbook. Simply change 'MyTemplate' to the full path & name of your template.

    The commented-out lines would print and close the new Word document, respectively.

  11. #11
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Re: Copying data from Excel to Word

    I have pasted the code in a module and changed 'MyTemplate' to the following path below, but I'm getting an error.

    Set wdDoc = wdapp.Documents.Add(Template:="S:\GUS\Excel\Purchasing log new\MyTemplate.dot")

    The error says 'Run time error 5151: Word was unable to read the document'

    Am I doing something wrong? I created a word template called MyTemplate in the directory above.
    I also tried to change it to the word doc I attached to my previous comment which is also in the same directory.

    I really appreciate the help.

    Gus

  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: Copying data from Excel to Word

    Was your template saved in the .dot format?

  13. #13
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Re: Copying data from Excel to Word

    I've sorted that part out it was .dotx, since I'm using excel 2007 I'm assuming?

    It created a word document from the template, but none of the data from excel was in the document i.e. the supplier info, date, reference etc.

  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: Copying data from Excel to Word

    Since you had saved in dotx format, you could have just added the 'x' to the template's extension in the code.

    As for the data not appearing, did you use the copy/paste special process before saving the template, so as to set up the links?

  15. #15
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Re: Copying data from Excel to Word

    Quote Originally Posted by macropod View Post
    As for the data not appearing, did you use the copy/paste special process before saving the template, so as to set up the links?
    Yeah I tried copy and paste special as HTML format but had no success still. It seems to be on the right track of what I am looking for, it's so close but so far away! I also tried to special paste as a Excel Worksheet object with no luck as well.

  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: Copying data from Excel to Word

    Double-click on the template. This will cause Word to create a new document from it. Then press Alt-F9. Do you see anything like:
    { LINK Excel.Sheet.8 "C:\\Users\\Mango2015\\Documents\\Copying-data-from-excel-to-word-example.xls" "PO Template!R9C9:R9C12" \a \f 4 \h }

  17. #17
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Re: Copying data from Excel to Word

    Opened the template and it created a new doc, but nothing happened when I pressed Alt + F9

  18. #18
    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: Copying data from Excel to Word

    Which means the template never had any links to the Excel workbook. You need to re-open the template for editing then do the copy/paste-link process I outlined in post #10: http://www.excelforum.com/showthread...=1#post4341128

  19. #19
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Re: Copying data from Excel to Word

    Quote Originally Posted by macropod View Post
    What you could do, given that the data from Excel always originates in the same set of cells, is to copy each block of Excel cells, then paste them into Word using Paste Special with the 'Paste Link' option and whichever of the Paste Link formats best meets your needs. No code required. Simply open the Word document and there the current data will be. Presumably, though, you'll want to save a separate copy of the document for each order and not have it updating every time the Excel data change. In that case, a small amount of code will be required and, instead of saving the document as a document, you'd save it as a Word template (.dot format).
    When you said copy each block of cell, did you mean the whole range or in parts? I may have found a work around to my problem but I'm not too sure about it so I would still like to try your solution. I'll give it a go again and then try ALT+F9

  20. #20
    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: Copying data from Excel to Word

    You could copy Excel cells A10-A15 as a group and paste them into the corresponding part of the Word table as a linked unit. You might equally copy Excel cells I9, I12 and I16 and paste them into the corresponding parts of the Word table as individual linked units.

  21. #21
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Re: Copying data from Excel to Word

    Quote Originally Posted by macropod View Post
    You could copy Excel cells A10-A15 as a group and paste them into the corresponding part of the Word table as a linked unit. You might equally copy Excel cells I9, I12 and I16 and paste them into the corresponding parts of the Word table as individual linked units.
    I finally got it to work... I was pasting it without selecting the link option. I apologize for dragging this on macropod, the link seems to 'un-link' if I move the table and this will insert an updated version of the table below the actual template in the word file.

    Don't see this being a big issue as once the word doc is created I can easily move the table and place it where I want it. Other than that it worked perfectly, much better than what I was going to use instead! Thank you I really appreciate it.

    Gus

  22. #22
    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: Copying data from Excel to Word

    Your reply suggests you're trying to paste the entire Excel 'table' into Word. Sure, you could do that, but I was only suggesting you paste the content of the cells you need to replicate.

  23. #23
    Registered User
    Join Date
    05-20-2015
    Location
    United Kingdom
    MS-Off Ver
    2003
    Posts
    34

    Re: Copying data from Excel to Word

    Quote Originally Posted by macropod View Post
    Your reply suggests you're trying to paste the entire Excel 'table' into Word. Sure, you could do that, but I was only suggesting you paste the content of the cells you need to replicate.
    That'd make more sense, sorry it's been a long day! I pasted a section of it when I tested it but I'll change it to what you suggested. Thanks again.

+ 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. Copying data from excel to word
    By tessda in forum Word Formatting & General
    Replies: 1
    Last Post: 03-12-2016, 10:41 PM
  2. Replies: 3
    Last Post: 12-10-2014, 10:38 AM
  3. Replies: 0
    Last Post: 05-16-2014, 11:07 AM
  4. Copying data from multiple word docs into one excel sheet
    By X82 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-15-2013, 07:24 AM
  5. Replies: 1
    Last Post: 03-11-2013, 05:37 AM
  6. Copying excel to word
    By philmetz in forum Excel General
    Replies: 1
    Last Post: 08-31-2009, 05:05 AM
  7. Copying Excel Data to Word
    By Flower R in forum Excel General
    Replies: 2
    Last Post: 12-28-2008, 07:20 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