+ Reply to Thread
Results 1 to 5 of 5

code to export excel table to word

Hybrid View

  1. #1
    mcope
    Guest

    code to export excel table to word

    I have created in Excel a number of automated tables on separate worksheets
    and would like to export these tables to Word through use of a macro. The
    tables all have similar formats (i.e. headings and width) but can vary in
    length. So far I have succeeded in placing them in Word but cannot
    automatically insert page breaks between each table, which is key for this
    particular project. I am working in VBA in Excel in order to create this
    Word application. I'm fairly certain that the code will not accept any
    reference to "Selection" (e.g. table, paragraph, etc.). Any ideas on how to
    insert these page breaks?

  2. #2
    Forum Contributor
    Join Date
    12-11-2004
    MS-Off Ver
    2007
    Posts
    137
    Hello

    to insert Pages Break in Word document , you may try

    WordDoc.Content.InsertBreak Type:=wdSectionBreakNextPage


    Regards
    michel

  3. #3
    mcope
    Guest

    Re: code to export excel table to word

    This line of code returns an error saying the parameter value is not in the
    acceptable range. Since the only content in the document itself is just
    several tables, the program only assumes that there is one paragraph
    (although there is also insertparagraph commands within the code) so it
    cannot distinguish between sections between tables.

    "michelxld" wrote:

    >
    > Hello
    >
    > to insert Pages Break in Word document , you may try
    >
    > WordDoc.Content.InsertBreak Type:=wdSectionBreakNextPage
    >
    >
    > Regards
    > michel
    >
    >
    > --
    > michelxld
    > ------------------------------------------------------------------------
    > michelxld's Profile: http://www.excelforum.com/member.php...o&userid=17367
    > View this thread: http://www.excelforum.com/showthread...hreadid=389879
    >
    >


  4. #4
    Forum Contributor
    Join Date
    12-11-2004
    MS-Off Ver
    2007
    Posts
    137
    Hello

    this macro copy excel tables ( named Tableau1 , Tableau2 ...) in a new Word document , and insert page break between each table


    Sub EnvoyerTableauxExcelVersWord()
    'activate Microsoft Word xx.x Object Library
    Dim AppWord As Word.Application
    Dim i As Byte

    Set AppWord = New Word.Application
    AppWord.Visible = True
    AppWord.Documents.Add

    For i = 1 To 4 'table number
    'each table is named "Tableau1" , "Tableau2" ....

    Range("Tableau" & i).Copy

    With AppWord.Selection
    .Paste
    .InsertBreak Type:=wdSectionBreakNextPage 'page break
    End With

    Next i

    Application.CutCopyMode = False
    End Sub


    Regards
    michel

  5. #5
    mcope
    Guest

    Re: code to export excel table to word

    Thanks for the help so far Michel, but the .InsertBreak command does not seem
    to be working in this particular application. I've also tried to send
    command keys (Ctrl + Enter) to Word in order to insert a page break but since
    I'm working from Excel, the macro does not want to accept that I'd want to
    send those key combinations to the Word application even though defined. Are
    there any other alternatives out there that I can try? This may just be a
    lost cause.

    "michelxld" wrote:

    >
    > Hello
    >
    > this macro copy excel tables ( named Tableau1 , Tableau2 ...) in a new
    > Word document , and insert page break between each table
    >
    >
    > Sub EnvoyerTableauxExcelVersWord()
    > 'activate Microsoft Word xx.x Object Library
    > Dim AppWord As Word.Application
    > Dim i As Byte
    >
    > Set AppWord = New Word.Application
    > AppWord.Visible = True
    > AppWord.Documents.Add
    >
    > For i = 1 To 4 'table number
    > 'each table is named "Tableau1" , "Tableau2" ....
    >
    > Range("Tableau" & i).Copy
    >
    > With AppWord.Selection
    > .Paste
    > .InsertBreak Type:=wdSectionBreakNextPage 'page break
    > End With
    >
    > Next i
    >
    > Application.CutCopyMode = False
    > End Sub
    >
    >
    > Regards
    > michel
    >
    >
    > --
    > michelxld
    > ------------------------------------------------------------------------
    > michelxld's Profile: http://www.excelforum.com/member.php...o&userid=17367
    > View this thread: http://www.excelforum.com/showthread...hreadid=389879
    >
    >


+ 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