Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

insert an image in front of text in a table using word vba

Posted on 2010-09-20
7
Medium Priority
?
1,175 Views
Last Modified: 2012-05-10
I have a word document with a table in it. in one of the cells I want to insert an image. The image needs to stay put in that cell (if I add rows above it, for example) but also needs to be able to be in front of text. I would like to be able to adjust the placement relative to its insertion point, using vba. I am stumped on how to achieve all (or at least most) of  this.
0
Comment
Question by:karimjohnson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 33723386
This interprets 'in front of' as  'earlier in the document than existing text within the cell.'
Sub InsertPictureInCell()
    Dim tbl As Table
    Dim cl As Cell
    Dim rng As Range
    Dim ilsh As InlineShape
    
    Set tbl = ActiveDocument.Tables(1)
    Set cl = tbl.Cell(3, 2)
    Set rng = cl.Range
    Debug.Print rng.Text
    rng.Collapse wdCollapseStart
    Set ilsh = ActiveDocument.InlineShapes.AddPicture("C:\MyFolder\MyPicture.jpg", False, True, rng)
    'ilsh.LockAspectRatio = True
    'ilsh.Width = CentimetersToPoints(3)
    
End Sub

Open in new window

0
 

Author Comment

by:karimjohnson
ID: 33725227
Is there a way to:

1. Allow the image to overlap the rows above and below (the image should typically be larger than the cell height, but I don't want the cell height to expand)

2. set the cell location dynamically? (for example, I have been trying to use a bookmark within the cell, so that whatever row the cell ends up on, I have an easy way to find it)
0
 

Author Comment

by:karimjohnson
ID: 33726077
playing around a bit with it I am able to set the range to the range of a bookmark (which is set to a cell). However, I still have the problem that the image expands the cell height rather than overlaps the adjacent cell(s). I can fix this by manually going into format/picture and setting to in front of text, but I need this to be automated somehow.
0
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 33728633
You may find it better to use a Shape object, which can be dragged to virtually any position, but it is very difficult to align this to cell boundaries, and even more difficult to keep there in then light of user intervention.

0
 

Author Comment

by:karimjohnson
ID: 33730081
It seems to work fine if I use your code, then follow a series of manual steps (select format->picture, select Layout Tab, select In Front of Text, press Ok. then move the image as desired with arrow keys or mouse.  Are you saying that you don't know how to automate that? Or that it cannot be automated?
0
 
LVL 50
ID: 34308509
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question