Hello Ernie,
ernie mil said:
I have a similar project inserting maps. I would like to know how to get excel to find the image by file name based on what is entered in Cell A1 AND automatically insert the map image.
Example:
Cell A1 = "N01"
For cell D5: Automatically find bmp file "N01.bmp" in MapsFolder and insert the file in Cell D5
This looks like a slightly different animal. How about something like the following:
<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> Chk_Insrt()
<SPAN style="color:darkblue">Dim</SPAN> fso <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Object</SPAN>, MyDir <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, Nme <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, myPic <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Object</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> ws <SPAN style="color:darkblue">As</SPAN> Worksheet
<SPAN style="color:darkblue">Set</SPAN> fso = CreateObject("Scripting.FileSystemObject")
MyDir = "c:\temp\" <SPAN style="color:green">'Change Directory</SPAN>
Nme = Sheets(1).[a1] & ".bmp" <SPAN style="color:green">'Change Filename</SPAN>
<SPAN style="color:darkblue">If</SPAN> fso.FileExists(MyDir & Nme) <SPAN style="color:darkblue">Then</SPAN>
Application.ScreenUpdating = 0
<SPAN style="color:darkblue">Set</SPAN> ws = Sheets(1) <SPAN style="color:green">'Change the target sheet</SPAN>
<SPAN style="color:darkblue">Set</SPAN> myPic = ws.Pictures.Insert(MyDir & Nme)
<SPAN style="color:darkblue">With</SPAN> myPic
.Top = ws.[d5].Top
.Left = ws.[d5].Left
.ShapeRange.Height = ws.[d5].RowHeight * 4.2 <SPAN style="color:green">'4.2 rows tall</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>
<SPAN style="color:darkblue">Set</SPAN> myPic = Nothing: <SPAN style="color:darkblue">Set</SPAN> ws = <SPAN style="color:darkblue">Nothing</SPAN>
Application.ScreenUpdating = 1
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">Set</SPAN> fso = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>
Don't necessarily see the need for a full-blown search here. Hope this helps.