ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   code to export excel table to word (https://www.excelbanter.com/excel-programming/335429-code-export-excel-table-word.html)

mcope

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?

michelxld[_17_]

code to export excel table to word
 

Hello

to insert Pages Break in Word document , you may try

WordDoc.Content.InsertBreak Type:=wdSectionBreakNextPage


Regards
miche

--
michelxl
-----------------------------------------------------------------------
michelxld's Profile: http://www.excelforum.com/member.php...fo&userid=1736
View this thread: http://www.excelforum.com/showthread.php?threadid=38987


mcope

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



michelxld[_18_]

code to export excel table to word
 

Hello

this macro copy excel tables ( named Tableau1 , Tableau2 ...) in a ne
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
miche

--
michelxl
-----------------------------------------------------------------------
michelxld's Profile: http://www.excelforum.com/member.php...fo&userid=1736
View this thread: http://www.excelforum.com/showthread.php?threadid=38987


mcope

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




All times are GMT +1. The time now is 10:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com