Centre pictures copied into a word table from excel worksheets

Mike UK

New Member
Joined
Dec 14, 2011
Messages
43
I have an excel workbook where a number of charts and tables are copied into word. Dotted through the word document there are several single cell word tables which are used to reference where each excel object needs to be pasted. The simplest way I have found to do this is by copying the excel data as a picture and pasting into the correct table in word. The code works fine,

The one small annoyance is that the pictures aren't centre aligned within the tables even though the tables have centre alignment set in the word template. It is necessary at the end to go through the document and for each picture (embedded in each table) the user has to Format > Align > Align Centre to correct.

Below is a sample of the code used to copy the pictures over.

'Copy Excel Table Range for requirements
r = 0
While Worksheets("requirements").Cells(26 + r, 2).Value <> ""
r = r + 1
Wend
Worksheets("Requirements").Range("B5:J" & (26 + r - 1)).CopyPicture

'Paste Table into MS Word
myDoc.Tables(1).Range.Select
myDoc.Tables(1).Range.PasteSpecial _
Link:=False, _
DataType:=wdPasteEnhancedMetafile, _
Placement:=wdFloatOverText, _
DisplayAsIcon:=False
'Placement:=wdInLine, _


'Autofit Table so it fits inside Word Document (MK - I can't see any difference this makes but plese check)
Set WordTable = myDoc.Tables(1)
WordTable.AutoFitBehavior (wdAutoFitWindow)

'Copy Excel Table Range
Worksheets("Portfolio Structure").Range("D2:K62").CopyPicture

'Paste Table into MS Word
myDoc.Tables(2).Range.Select
myDoc.Tables(2).Range.PasteSpecial _
Link:=False, _
DataType:=wdPasteEnhancedMetafile, _
Placement:=wdFloatOverText, _
DisplayAsIcon:=False
'Placement:=wdInLine

Any ideas? Thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Change the paragraph alignment in your Word tables to 'centre', and change:
Placement:=wdFloatOverText
to:
Placement:=wdInLine

There is also no need for:
myDoc.Tables(2).Range.Select
All that does is slow down your code.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top