Converting Word table to GIF JPG or PNG

K

Knarf49

I need to create GIF files of word tables respecting precise size
(height width) for upload to a web page using a CMS program. In order
to fix limits I put the tables inside a "text box" where I have set
the pixels limits as I need them. Then the authors of the tables know
that they have to stick with the box limits.
I use different table styles to format the tables and realise that
when I paste the text box (with the table inside) as picture inside
the Word document, or directly into Office Picture Manager, I get the
right size in pixels and also most of the table format, but bold type
and font type/size/alignment change if different from the normal.dot
choice. I hoped that it would be solved that issue going from Office
2003 to Office 2007, but no!
So if I want a correct result, I need each time before copying the
text box to:
- select the textbox
- chose the font I want to use
- apply bold
- take away bold where I don't want it (I need it only for head row
and left column)
Then I can copy and paste and the result is OK. But no way to do the
above corrections using a macro-command!
The issue is well known and due to mix of table and paragraph style
priorities:
http://www.shaunakelly.com/word/tablestyles/index.html
There is another solution: I can make a screen shot of the tables and
paste, but it is not a fast solution if you want to keep the
dimensions etc.
Anyone got an idea to macro or other to do this job?
Regards
Knarf
 
P

pabsfx-01

Anyone got an idea to macro or other to do this job?

Click on a cell in a table in a text box and run the following code, I
believe it will do what you described:

Sub FormatTableInTextBox()

If Selection.Tables.Count = 1 And Selection.ShapeRange.Count = 1
Then
'Ensure one table in a textbox is selected

'Unbold the table
Selection.Expand wdTable
Selection.Font.Bold = False

'Select the desired font for the table
Selection.Font.Name = "Arial"
Selection.Font.Size = 8

'Bold top row and left column
Selection.StartOf Unit:=wdTable
Selection.SelectRow
Selection.Font.Bold = True
Selection.StartOf Unit:=wdTable
Selection.SelectColumn
Selection.Font.Bold = True
Selection.StartOf Unit:=wdTable

'Select the text box that contains the table
Selection.ShapeRange.Select
Selection.Cut

'Replace it with a .GIF
Selection.PasteSpecial Link:=False, DataType:=13, Placement:=
_
wdInLine, DisplayAsIcon:=False 'Could also be
wdFloatOverText instead of wdInLine
Else
MsgBox "Select a table in a text box before running this
macro.", , "Select Table"
End If

End Sub
 
K

Knarf49

Click on a cell in a table in a text box and run the following code, I
believe it will do what you described:

Sub FormatTableInTextBox()

If Selection.Tables.Count = 1 And Selection.ShapeRange.Count = 1
Then
'Ensure one table in a textbox is selected

'Unbold the table
Selection.Expand wdTable
Selection.Font.Bold = False

'Select the desired font for the table
Selection.Font.Name = "Arial"
Selection.Font.Size = 8

'Bold top row and left column
Selection.StartOf Unit:=wdTable
Selection.SelectRow
Selection.Font.Bold = True
Selection.StartOf Unit:=wdTable
Selection.SelectColumn
Selection.Font.Bold = True
Selection.StartOf Unit:=wdTable

'Select the text box that contains the table
Selection.ShapeRange.Select
Selection.Cut

'Replace it with a .GIF
Selection.PasteSpecial Link:=False, DataType:=13, Placement:=
_
wdInLine, DisplayAsIcon:=False 'Could also be
wdFloatOverText instead of wdInLine
Else
MsgBox "Select a table in a text box before running this
macro.", , "Select Table"
End If

End Sub

Thanks a lot for your suggestion. However it creates GIF's which are
4/3 too big and thus not sharp (same result with a manual copy and
paste as GIF).

By using DataType:=15 instead of 13, the size is OK, but still lack of
sharpness - I don't know where that little lack of resolution comes
from...

Finally, I would like to preserve my table in Word, and in this case
it is cut and replaced with a picture. Is possible to paste in picture
program and then go back to Word and cancel operations to recover the
table.

Thanks
Knarf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top