+ Reply to Thread
Results 1 to 4 of 4

Pasting table from Excel 2013 to Word 2013 with VBA

  1. #1
    Registered User
    Join Date
    10-16-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    2

    Pasting table from Excel 2013 to Word 2013 with VBA

    Hi all,

    Although I have quite a bit of experience with Excel VBA I have little experience with Word VBA and have run into a bit of an odd issue.

    I have the following table in Excel:

    1.JPG

    I am using VBA across Excel and Word to build a report, in Word format, from one of my spreadsheets. Essentially I am copying this table into the clipboard and then attempting to paste it into a Word document.

    If I paste it using the Word GUI, without VBA, it looks like this in Word. This is exactly what I want. As you can see, the spacing in the cells is maintained.

    2.JPG

    If I record that action as a macro in Word I get the following:

    Please Login or Register  to view this content.
    Having looked this up I can see what it's doing and understand the parameters. The strange thing is, if I run the recorded Macro from Word or try to use the same code my Excel file the table pastes into the Word document but the formatting is all screwed up:

    3.JPG

    It's as if Word has decided to insert a TAB between the cell wall and text for each of my cells and therefore shifted all of the text to the right. Although the top left cell is fine.

    Hopefully someone has some ideas because i've hit a brick wall. It's probably also worth saying that I have tried the following with similar results although it works fine through the Word GUI:

    Please Login or Register  to view this content.
    Please help as I don't really want to have to write code to go through each cell and delete the phantom additional characters.

    Many Thanks

    Simon

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pasting table from Excel 2013 to Word 2013 with VBA

    Simon

    Can you post the rest of the code?

    Also, where are you running the code from?
    If posting code please use code tags, see here.

  3. #3
    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: Pasting table from Excel 2013 to Word 2013 with VBA

    Did you consider just using Selection.Paste, which is what pasting through the GUI defaults to?
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    Registered User
    Join Date
    10-16-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Pasting table from Excel 2013 to Word 2013 with VBA

    Quote Originally Posted by Norie View Post
    Simon

    Can you post the rest of the code?

    Also, where are you running the code from?
    Hi, thanks for replying.

    In this example I have tried running the code from Excel and Word with the same results. I did however do the right thing and tried an empty Word file and it worked just fine. I have now rebuilt the Word file back into the template document and it's all working great. I am guessing that there was a setting or corruption in my document which was causing me problems.

+ 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. instal stand alone EXCEL 2013 on OFFICE 2013 home and business
    By LukasLyziciar in forum Excel General
    Replies: 0
    Last Post: 06-19-2015, 03:41 AM
  2. Excel 2013 and Access 2013 as Pivot Table External Data Source
    By Grimnebulin in forum Access Tables & Databases
    Replies: 1
    Last Post: 05-27-2015, 02:13 PM
  3. No PowerPivot in Com Add ins Excel 2013 (Microsoft office professional plus 2013)
    By benoj2005 in forum PowerPoint Formatting & General
    Replies: 7
    Last Post: 09-18-2014, 09:13 AM
  4. [SOLVED] No Colour Formatting in Excel 2013 and Word 2013
    By pt68 in forum Excel General
    Replies: 4
    Last Post: 09-15-2014, 03:25 PM
  5. Replies: 3
    Last Post: 07-20-2014, 11:46 AM
  6. Replies: 0
    Last Post: 08-28-2013, 06:45 AM
  7. Link Excel 2013 to Word 2013
    By drosen99 in forum Word Formatting & General
    Replies: 20
    Last Post: 02-26-2013, 08: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