+ Reply to Thread
Results 1 to 2 of 2

VBA to copy X rows of data from Excel to Word table

Hybrid View

  1. #1
    Registered User
    Join Date
    06-17-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    1

    Post VBA to copy X rows of data from Excel to Word table

    Hi

    I have some experience in using Excel but I have little experience in using VBA.

    I am trying to find a way to copy rows of data from a Excel 2007 spreadsheet into a table in a Word template using VBA.

    There are 10 columns in the spreadsheet but the number of rows could vary from between 1 to 30 each time it is created. There are also 5 rows of report information above the data, which I would want to ignore (I have added an example of what the spreadsheet might look like).

    I have found various posts which discuss ways to copy data from Excel to Word , but nothing quite fits with what I am trying to do.

    I would appreciate any guidance on how to do this.

    GN1664
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: VBA to copy X rows of data from Excel to Word table

    ' In the VBE go to Tools -> References
    ' Check: Microsoft Word 12.0 Object Library
    Sub CreateTableInWord()
        Dim wdApp As Word.Application
        Dim wdDoc As Document
        Dim wdRg As Word.Range
        Dim nLastRow As Long
        
        Set wdApp = New Word.Application
        Set wdDoc = wdApp.documents.Add
        wdApp.Visible = True
        Set wdRg = wdDoc.Range
        
        nLastRow = Cells(Rows.Count, "A").End(xlUp).Row
        Range("A5:J" & nLastRow).Copy
        wdRg.Paste
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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