+ Reply to Thread
Results 1 to 6 of 6

Creating a MS Word Document from Excel

  1. #1
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Creating a MS Word Document from Excel

    Hi everyone,

    I am very new to VBA and I am hoping one of the experts on this forum is able to help me out. Any insight or experience from any member is very much appreciated

    I am currently trying to write a script that takes various information from my work book and make a word document out of it. Basically, what I want to do is:
    1) write some stuff in the word doc
    2) copy/paste a table from spreadsheet to word doc
    3) write more stuff
    4) copy/paste more stuff

    I am able to write lines proeprly, but I am unable to copy/paste properly. Whenever I try to paste something from the spreadsheet to the word doc, it pastes at the top of the word doc, overwriting anything that was at the top of the document. It seems very simple but I think i am missing a key line or two.

    The skeleton of my code goes like this:


    Please Login or Register  to view this content.
    Last edited by jason_lee_91; 07-26-2012 at 03:09 PM. Reason: Replaced Quote Tags with Code Tags

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Creating a MS Word Document from Excel

    Change this...
    Please Login or Register  to view this content.
    To this...
    Please Login or Register  to view this content.
    This will now paste at the last inserted paragraph.

  3. #3
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Creating a MS Word Document from Excel

    thank you this is exactly what i was looking for!

    one other thing. I have noticed that the formatting of the tables are a little different through the macro vs when i copy/paste manually. is there a way to make the vba copy/paste exactly the same way that i would?? it appears as if all the spaces and what not are no longer in the cells and only the text which makes all the cells smaller and weird sizes

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Creating a MS Word Document from Excel

    Quote Originally Posted by jason_lee_91 View Post
    thank you this is exactly what i was looking for!

    one other thing. I have noticed that the formatting of the tables are a little different through the macro vs when i copy/paste manually. is there a way to make the vba copy/paste exactly the same way that i would?? it appears as if all the spaces and what not are no longer in the cells and only the text which makes all the cells smaller and weird sizes
    Try something like this. Instead of just .Paste, use .PasteExcelTable

    Please Login or Register  to view this content.
    Experiment with RTF set to either TRUE or FALSE


    Or try .PasteAndFormat
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Creating a MS Word Document from Excel

    excellent!
    thank you very much! how do i mark this thread as solved?

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Creating a MS Word Document from Excel

    Quote Originally Posted by jason_lee_91 View Post
    excellent!
    thank you very much! how do i mark this thread as solved?
    You're welcome.

    Quote Originally Posted by Forum Rules
    9. Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.

+ 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