Centre pictures copied into a word table from excel worksheets

Mike UK

New Member
Joined
Dec 14, 2011
Messages
28
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
 

Macropod

Retired Moderator
Joined
Aug 27, 2007
Messages
3,312
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.
 

Forum statistics

Threads
1,081,561
Messages
5,359,612
Members
400,540
Latest member
JimUSMC

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top