By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

insert picture in word through vb

100+
P: 138
hi everyone
i have a problem, i just export the data from data grid to the word file, but now the problem is i want to insert the picture in the word with the path name in the grid.

for ex;
i have three fields in the data grid
1 name
2. address
3 pic path

i just exported the name, address and the path name of the picture but can't insert the actual picture.
plz experts, help
with best regards
Apr 27 '07 #1
Share this Question
Share on Google+
5 Replies


SammyB
Expert 100+
P: 807
Something like this:
Expand|Select|Wrap|Line Numbers
  1. ActiveDocument.Shapes.AddPicture _
  2.         FileName:="C:\My Pictures\Demo.JPG", _
  3.         Left:=100, Top:=200, SaveWithDocument:=True
Apr 27 '07 #2

100+
P: 138
thanx SammyB for the answer
it did work but i want it to be opened in the tabular form. i,e. all other informations are displayed in the table, so i want the picture of the corresponding name should be displayed in the same row.

name---------------------------add --------------------------------------------pic
abc --------------------------xyz---------------------------------------------pic of abc
abc1 --------------------------xyz1---------------------------------------------pic of abc1

i used the following code :

oDoc.Tables(1).Columns(1).Cells(1).Range.Text = fg.TextMatrix(1, 1)
oDoc.Tables(1).Columns(2).Cells(1).Range.Text = fg.TextMatrix(1, 2)
oDoc.Tables(1).Columns(3).Cells(1).Range.Text = fg.TextMatrix(1, 3) "Error for the photo"

but the image is not displayed in the table
but only outside the table.
thanx
Apr 30 '07 #3

SammyB
Expert 100+
P: 807
You just need to use InlineShapes:
Expand|Select|Wrap|Line Numbers
  1.  oDoc.Tables(1) .Columns(3).Cells(2).Range.InlineShapes.AddPicture FileName:=....
Apr 30 '07 #4

100+
P: 138
thanx SammyB for that helpful suggestion
one more question
what if i show the data in the page not in the table. that means the name, then the pic of that name in the next line , and at the bottom the address of that name. all in the separate line.
is it possible to show it and the information of another name in the next page and so on.
thanx
May 1 '07 #5

SammyB
Expert 100+
P: 807
thanx SammyB for that helpful suggestion
one more question
what if i show the data in the page not in the table. that means the name, then the pic of that name in the next line , and at the bottom the address of that name. all in the separate line.
is it possible to show it and the information of another name in the next page and so on.
thanx
Actually, I don't know how to do any of this. :D I just record a macro and look at the code, and post it for you. None of the Office products have that difficult an object model. Try recording a macro and see what you can do. Note, Word is a little tough because you cannot navigate thru the document with the mouse while in the Macro Recorder. So, before you start, look at Help, Keyboard Shrotcuts, Move the Insertion Point. HTH --Sam
May 1 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.