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 / October 2005

Tip: Looking for answers? Try searching our database.

Putting an image in a table cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hals_left - 27 Oct 2005 14:05 GMT
I have some code (below) that creates table rows and writes data from a
database, and symbols to the new cells.

I have a small image that needs to go into each row too, If I have the
image in the first row is there anyway to put it into each new row
created ?

Thanks
hals_left

ActiveDocument.Tables(3).Rows.Add
With ActiveDocument.Tables(3).Rows(ActiveDocument.Tables(3).Rows.Count
- 1)
   .Cells(1).Select
   Selection.Text = objRS("ID")

   .Cells(2).Select
   Selection.Text = objRS("Name")

   If objRS("Selected") = "1" Then
      .Cells(3).Select
      Selection.End = Selection.End - 1
      Selection.InsertSymbol Font:="Wingdings",
CharacterNumber:=-3844, Unicode:=True
   End If

   ' How to do this part ?
   .Cells(4).Select
   Selection.Contents = Copy a gif image from another table cell or
import it from file ?
zkid - 27 Oct 2005 18:34 GMT
Have you tried placing the graphic in the clipboard and then just pasting it
into the current cell?  If the graphic is too squirelly and doesn't paste in
the correct location, then what I do with client letterhead is create a table
with the grapic in another document, then I copy the whole table and paste it
into the needed location.  Just make sure the table dimensions are the same
as the row you need to add.

Hope this helps.  zkid

> I have some code (below) that creates table rows and writes data from a
> database, and symbols to the new cells.
[quoted text clipped - 26 lines]
>     Selection.Contents = Copy a gif image from another table cell or
> import it from file ?
Jean-Guy Marcil - 27 Oct 2005 19:26 GMT
hals_left was telling us:
hals_left nous racontait que :

> I have some code (below) that creates table rows and writes data from
> a database, and symbols to the new cells.
[quoted text clipped - 26 lines]
>    Selection.Contents = Copy a gif image from another table cell or
> import it from file ?

The easiest by far would be to store the Image as an AutoText entry in the
Attached Template if there is one.
Make sure that the AutoText entry has a unique name.
Also, try to avoid using the Selection object. The Range object is faster
and more reliable:

'_______________________________________
Dim TargetTable As Table

Set TargetTable = ActiveDocument.Tables(3)

With TargetTable
   .Rows.Add

   With .Rows(TargetTable.Rows.Count - 1)
       .Cells(1).Range.Text = objRS("ID")

       .Cells(2).Range.Text = objRS("Name")

       If objRS("Selected") = "1" Then
          With .Cells(3).Range
               .Collapse wdCollapseStart
               .InsertSymbol CharacterNumber:=-3844, _
                   Font:="Wingdings", Unicode:=True
           End With
       End If

   ' How to do this part ?
       With .Cells(4).Range
           .Text = "Name of AutoText Entry"
           .MoveEnd wdCharacter, -1
           .InsertAutoText
       End With
'Selection.Contents = Copy a gif image from another table cell or
'import it from file ?
   End With

End With
'_______________________________________

If the autotext way in not possible, try this version which assumes that the
image already exists in the fourth cell of the second row.

'_______________________________________
Dim TargetTable As Table
Dim SourceRange As Range

Set TargetTable = ActiveDocument.Tables(3)

With TargetTable
   .Rows.Add

   With .Rows(TargetTable.Rows.Count - 1)
       .Cells(1).Range.Text = objRS("ID")

       .Cells(2).Range.Text = objRS("Name")

       If objRS("Selected") = "1" Then
          With .Cells(3).Range
               .Collapse wdCollapseStart
               .InsertSymbol CharacterNumber:=-3844, _
                   Font:="Wingdings", Unicode:=True
           End With
       End If

   ' How to do this part ?
       Set SourceRange = TargetTable.Cell(2, 4).Range
       SourceRange.MoveEnd wdCharacter, -1
       .Cells(4).Range.FormattedText = SourceRange

'Selection.Contents = Copy a gif image from another table cell or
'import it from file ?
   End With

End With
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

 
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.