Replacing a picture with a table, huge problem. Please

M

Mike

Hi! Here’s my problem:

I get over 1000 documents each day that I need to put into a newsletter.
Some of these documents have pictures, charts and graphs embedded.
When the Vertical alignment property for those pictures is set to Absolute,
then when I do mySelection.InsertFile() the pictures stay where they are and
do not move to the next page or down. That “side effect†caused me to spend
my Super Bowl weekend manually reformatting them.

I figured out that if I create a table in the exact location where the
picture is located, and place the picture in it, then this table can move
with the rest of the text. I have no problem creating a table. I can not to
position it where the picture used to be.

I created a file to illustrate my problem.
It can be downloaded at http://www.freefilehosting.net/?id=q939laXe


What am I doing wrong? Here’s my code:

Dim i As Integer
Dim sh As shape
Dim w As Single
Dim h As Single
Dim x As Single
Dim y As Single

For i = ActiveDocument.Shapes.Count To 1 Step -1

Dim tbl As Table
Dim rng As range
Dim frm As Frame
Dim ish As InlineShape

Set sh = ActiveDocument.Shapes(i)
sh.Anchor.Delete ‘ Does not seem to delete anything


w = sh.Width
h = sh.Height
x = sh.Left
y = sh.Top


'Set tbl = rng.ConvertToTable
'tbl.Columns.PreferredWidth = w
'tbl.Rows.SetHeight h, wdRowHeightExactly

If sh.Type = msoPicture Then
sh.Select


'Set tbl = Selection.range.ConvertToTable
Selection.Cut
Set tbl = Selection.Tables.Add(Selection.range, 1, 1,
wdWord9TableBehavior, WdAutoFitBehavior.wdAutoFitContent)

tbl.AllowPageBreaks = True
tbl.Columns.PreferredWidth = w
tbl.Rows.SetHeight h, wdRowHeightExactly
tbl.ApplyStyleHeadingRows = True
tbl.ApplyStyleLastRow = True
tbl.ApplyStyleFirstColumn = True
tbl.ApplyStyleLastColumn = True

tbl.Columns.Item(1).Cells.Item(1).range.Paste

End If
Next

Thank you in advance,
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TWlrZQ==?=,
I get over 1000 documents each day that I need to put into a newsletter.
Some of these documents have pictures, charts and graphs embedded.
When the Vertical alignment property for those pictures is set to Absolute,
then when I do mySelection.InsertFile() the pictures stay where they are and
do not move to the next page or down. That “side effect†caused me to spend
my Super Bowl weekend manually reformatting them.

I figured out that if I create a table in the exact location where the
picture is located, and place the picture in it, then this table can move
with the rest of the text. I have no problem creating a table. I can not to
position it where the picture used to be.
Why not just change the Shape's properties to move with the text? See the
RelativeVerticalPosition property in the object model help.
I created a file to illustrate my problem.
It can be downloaded at http://www.freefilehosting.net/?id=q939laXe


What am I doing wrong? Here’s my code:

Dim i As Integer
Dim sh As shape
Dim w As Single
Dim h As Single
Dim x As Single
Dim y As Single

For i = ActiveDocument.Shapes.Count To 1 Step -1

Dim tbl As Table
Dim rng As range
Dim frm As Frame
Dim ish As InlineShape

Set sh = ActiveDocument.Shapes(i)
sh.Anchor.Delete ‘ Does not seem to delete anything


w = sh.Width
h = sh.Height
x = sh.Left
y = sh.Top


'Set tbl = rng.ConvertToTable
'tbl.Columns.PreferredWidth = w
'tbl.Rows.SetHeight h, wdRowHeightExactly

If sh.Type = msoPicture Then
sh.Select


'Set tbl = Selection.range.ConvertToTable
Selection.Cut
Set tbl = Selection.Tables.Add(Selection.range, 1, 1,
wdWord9TableBehavior, WdAutoFitBehavior.wdAutoFitContent)

tbl.AllowPageBreaks = True
tbl.Columns.PreferredWidth = w
tbl.Rows.SetHeight h, wdRowHeightExactly
tbl.ApplyStyleHeadingRows = True
tbl.ApplyStyleLastRow = True
tbl.ApplyStyleFirstColumn = True
tbl.ApplyStyleLastColumn = True

tbl.Columns.Item(1).Cells.Item(1).range.Paste

End If
Next

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in
the newsgroup and not by e-mail :)
 
M

Mike

Hi! Thank you for taking a look. If you unzip the test document you may see
that the picture has been configured to move with the text, yet it does not
move. Also, since my documents are complex, setting Move with Text property
causes other layout problems. I figured that if I place a table in the exact
location of the picture and then copy the picture into the table I can solve
all my formatting issues as tables seem to stay where they are and they move
properly.

Am I on the right track? What would you advise?
BTW, I am also grateful for your taking a look at my InsertFile() post
earlier.


Many thanks in advance,

--Michael
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TWlrZQ==?=,
If you unzip the test document you may see
that the picture has been configured to move with the text, yet it does not
move. Also, since my documents are complex, setting Move with Text property
causes other layout problems. I figured that if I place a table in the exact
location of the picture and then copy the picture into the table I can solve
all my formatting issues as tables seem to stay where they are and they move
properly.
As a general rule, I won't open files (unless I'm being paid to).

If you say the property is activated, I'll take your word for it .-)

However, I know of no *reliable* way to make sure a table is going to be in
exactly the same position as the graphic is/was. That said, using the macro
recorder to pick up the commands used to freely position the table on the page
yields:

With tbl.Rows
.WrapAroundText = True
.HorizontalPosition = wdTableLeft
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.DistanceLeft = CentimetersToPoints(0.32)
.DistanceRight = CentimetersToPoints(0.32)
.VerticalPosition = CentimetersToPoints(0)
.RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
.DistanceTop = CentimetersToPoints(0)
.DistanceBottom = CentimetersToPoints(0)
.AllowOverlap = False
End With


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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