ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copying Excel table to Word, with Formatting (https://www.excelbanter.com/excel-programming/396626-copying-excel-table-word-formatting.html)

Squeff

Copying Excel table to Word, with Formatting
 
I have an application that builds a nice looking table in Excel. The
end-user wants this to be as Word table, instead.

The spreadsheet has 10 columns (all equal width), although the columns
are merged in some rows.

I have a VBA routine (in Excel) that copies the spreadsheet and pastes
it into Word.

It looks good, but is too wide to fit on the page and it resizes the
columns inappropriately, so I issue this command
appWD.Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
to (at least) make it fit on the page. However, this resizes the
columns in a way different than I want them.

I'd like to be able to have my paste use the exact same relative
columns widths as the source.

I've tried
appWD.Selection.Tables(1).Columns.Width = 44.25
but this doesn't work because I have merged cells. I can't specify a
column index, because I then get a message that it can't refer to
specific column indexes because of the merged cells.

The end result has to be a normal Word table, so I can't make it a
graphic. I can't have Excel save as an RTF, because this strips a
good deal of my formatting.

Any ideas of how I can end up with an exact copy of my Excel
spreadsheet as a Word table? All formatting, save for the widths, is
perfect.


Kevin B

Copying Excel table to Word, with Formatting
 
Why not embed the Excel file as an object in Word? Would that work?
--
Kevin Backmann


"Squeff" wrote:

I have an application that builds a nice looking table in Excel. The
end-user wants this to be as Word table, instead.

The spreadsheet has 10 columns (all equal width), although the columns
are merged in some rows.

I have a VBA routine (in Excel) that copies the spreadsheet and pastes
it into Word.

It looks good, but is too wide to fit on the page and it resizes the
columns inappropriately, so I issue this command
appWD.Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
to (at least) make it fit on the page. However, this resizes the
columns in a way different than I want them.

I'd like to be able to have my paste use the exact same relative
columns widths as the source.

I've tried
appWD.Selection.Tables(1).Columns.Width = 44.25
but this doesn't work because I have merged cells. I can't specify a
column index, because I then get a message that it can't refer to
specific column indexes because of the merged cells.

The end result has to be a normal Word table, so I can't make it a
graphic. I can't have Excel save as an RTF, because this strips a
good deal of my formatting.

Any ideas of how I can end up with an exact copy of my Excel
spreadsheet as a Word table? All formatting, save for the widths, is
perfect.



Squeff

Copying Excel table to Word, with Formatting
 
On Aug 30, 2:20 pm, Kevin B wrote:
Why not embed the Excel file as an object in Word? Would that work?
--
Kevin Backmann


Unfortunately not. The customer wants the resultant table to act like
a Word table, not an Excel table. This may seem a subtle thing, but
there are some key differences. For example, Word will nicely
autosize rows (even for merged cells), while Excel will not.



All times are GMT +1. The time now is 02:53 AM.

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