Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Replacing a picture with a table, huge problem. Please   

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 06 Feb 2006 00:02 GMT
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,
Cindy M  -WordMVP- - 06 Feb 2006 10:11 GMT
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.
[quoted text clipped - 8 lines]
> 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
[quoted text clipped - 51 lines]
>         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 :-)
Mike - 06 Feb 2006 21:34 GMT
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

> Hi =?Utf-8?B?TWlrZQ==?=,
>
[quoted text clipped - 76 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply in
> the newsgroup and not by e-mail :-)
Cindy M  -WordMVP- - 08 Feb 2006 14:39 GMT
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
[quoted text clipped - 3 lines]
> 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 :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.