A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Insert image based on filename



 
 
Thread Tools Display Modes
  #1  
Old December 30th, 2009, 09:06 PM posted to microsoft.public.word.tables
Huber57
external usenet poster
 
Posts: 121
Default Insert image based on filename

Hello all:

I have searched high and low for an answer and I am stumped.

I have a table with two columns. In column A, I have the filename of an
image that I would like to insert into column B. There are over 1,000. Is
there any way to write a macro to insert all of them into Column B based on
the information in Column A? I found this macro for excel but I don't know
if it could be used as a starting point for Word.

Sub ABCD()
Dim pic As Picture
Dim sPath As String, sName As String
Range("B2").Select
sPath = "C:\Graphics\"
sName = Range("A2").Value
If LCase(Right(sName, 4)) ".png" Then
sName = sName & ".png"
End If
If Dir(sPath & sName) "" Then
Set pic = ActiveSheet.Pictures.Insert(sPath & sName)
With Range("B2")
pic.Top = .Top
pic.Left = .Left
End With
Else
MsgBox sPath & sName & " not found"
End If
End Sub

Any help would be greatly appreciated!

Sincerely,

Doug
  #2  
Old December 30th, 2009, 10:58 PM posted to microsoft.public.word.tables
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default Insert image based on filename

Are you using Excel or Word. Your use of ActiveSheet makes me think you are
working in Excel.

You could however use the information in the first column to do a mail merge
in Word that would insert the filenames and the pictures into a document.

See the "Graphics from data base" item under the "Special merges" section of
fellow MVP Cindy Meister's website at:

http://homepage.swissonline.ch/cindy...r/MergFram.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Huber57" wrote in message
...
Hello all:

I have searched high and low for an answer and I am stumped.

I have a table with two columns. In column A, I have the filename of an
image that I would like to insert into column B. There are over 1,000.
Is
there any way to write a macro to insert all of them into Column B based
on
the information in Column A? I found this macro for excel but I don't
know
if it could be used as a starting point for Word.

Sub ABCD()
Dim pic As Picture
Dim sPath As String, sName As String
Range("B2").Select
sPath = "C:\Graphics\"
sName = Range("A2").Value
If LCase(Right(sName, 4)) ".png" Then
sName = sName & ".png"
End If
If Dir(sPath & sName) "" Then
Set pic = ActiveSheet.Pictures.Insert(sPath & sName)
With Range("B2")
pic.Top = .Top
pic.Left = .Left
End With
Else
MsgBox sPath & sName & " not found"
End If
End Sub

Any help would be greatly appreciated!

Sincerely,

Doug


  #3  
Old January 5th, 2010, 03:05 PM posted to microsoft.public.word.tables
Huber57
external usenet poster
 
Posts: 121
Default Insert image based on filename

Doug,

Thank you for your note. The code listed below was from Excel. I
appreciate the link to Cindy's page.

It looks like I want to use the InsertPicture function. Here is how I would
like to use it.

I have a table with two columns:
Col A. lists the file name of a picture in each row
Col B. has a picture of the corresponding file name in the same row.

Example:
Col. A Col. B
duck.jpg (displays picture of a duck using InsertPicture function)

What i would like in Col. B is the InsertPicture function that references
the file in the same row in column A.

Is there a way to use InsertPicture and reference Col A and copy it down
column B? I have over 1,000 pictures that I need to do this with.

Sincerely,

Doug

"Doug Robbins - Word MVP" wrote:

Are you using Excel or Word. Your use of ActiveSheet makes me think you are
working in Excel.

You could however use the information in the first column to do a mail merge
in Word that would insert the filenames and the pictures into a document.

See the "Graphics from data base" item under the "Special merges" section of
fellow MVP Cindy Meister's website at:

http://homepage.swissonline.ch/cindy...r/MergFram.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Huber57" wrote in message
...
Hello all:

I have searched high and low for an answer and I am stumped.

I have a table with two columns. In column A, I have the filename of an
image that I would like to insert into column B. There are over 1,000.
Is
there any way to write a macro to insert all of them into Column B based
on
the information in Column A? I found this macro for excel but I don't
know
if it could be used as a starting point for Word.

Sub ABCD()
Dim pic As Picture
Dim sPath As String, sName As String
Range("B2").Select
sPath = "C:\Graphics\"
sName = Range("A2").Value
If LCase(Right(sName, 4)) ".png" Then
sName = sName & ".png"
End If
If Dir(sPath & sName) "" Then
Set pic = ActiveSheet.Pictures.Insert(sPath & sName)
With Range("B2")
pic.Top = .Top
pic.Left = .Left
End With
Else
MsgBox sPath & sName & " not found"
End If
End Sub

Any help would be greatly appreciated!

Sincerely,

Doug


  #4  
Old January 5th, 2010, 03:55 PM posted to microsoft.public.word.tables
Huber57
external usenet poster
 
Posts: 121
Default Insert image based on filename

All:

Here is what I was looking for. Sorry for the post.

http://www.gmayor.com/mail_merge_graphics.htm

Doug

"Doug Robbins - Word MVP" wrote:

Are you using Excel or Word. Your use of ActiveSheet makes me think you are
working in Excel.

You could however use the information in the first column to do a mail merge
in Word that would insert the filenames and the pictures into a document.

See the "Graphics from data base" item under the "Special merges" section of
fellow MVP Cindy Meister's website at:

http://homepage.swissonline.ch/cindy...r/MergFram.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Huber57" wrote in message
...
Hello all:

I have searched high and low for an answer and I am stumped.

I have a table with two columns. In column A, I have the filename of an
image that I would like to insert into column B. There are over 1,000.
Is
there any way to write a macro to insert all of them into Column B based
on
the information in Column A? I found this macro for excel but I don't
know
if it could be used as a starting point for Word.

Sub ABCD()
Dim pic As Picture
Dim sPath As String, sName As String
Range("B2").Select
sPath = "C:\Graphics\"
sName = Range("A2").Value
If LCase(Right(sName, 4)) ".png" Then
sName = sName & ".png"
End If
If Dir(sPath & sName) "" Then
Set pic = ActiveSheet.Pictures.Insert(sPath & sName)
With Range("B2")
pic.Top = .Top
pic.Left = .Left
End With
Else
MsgBox sPath & sName & " not found"
End If
End Sub

Any help would be greatly appreciated!

Sincerely,

Doug


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:19 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.