Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default insert picture


Hi how do you insert picture if you only know the filename not the extention
Pic$ is a six digit code, but the file if it exists can be .bmp, .gif, .jpeg
, .jpg
I want to insert if exists regardless of picture type.

Please help

Thanks

sunil

I have...

If Dir(Path$ & Pic$) < "" Then
ActiveSheet.Pictures.Insert(Path$ & Pic$).Select
Endif


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default insert picture


I'm not sure I understand your question; however, if Pic$ is a 6-digit
number only, you can do this to find a single file (there could be more than
one) that has that filename...

FileNameAndExtension = Dir(Path$ & Pic$ & ".*")
If Len(FileName) 0 Then
ActiveSheet.Pictures.Insert(FileName).Select

The dot in the dot-asterisk (.*) that I added signifies an extension and the
asterisk says that extension can be anything. I'm assuming you don't have,
say, txt file in that directory with the same filename part, otherwise you
will have to filter them out using a loop of some kind.

--
Rick (MVP - Excel)


"sunilpatel" wrote in message
...
Hi how do you insert picture if you only know the filename not the
extention
Pic$ is a six digit code, but the file if it exists can be .bmp, .gif,
.jpeg , .jpg
I want to insert if exists regardless of picture type.

Please help

Thanks

sunil

I have...

If Dir(Path$ & Pic$) < "" Then
ActiveSheet.Pictures.Insert(Path$ & Pic$).Select
Endif


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default insert picture


dim exts as string
dim bFound as boolean
for i = 1 to 3
select case i
case 1: exts =".bmp"
case 2: exts ="..gif"
case 3: exts =".jpeg"
end select

If Dir(Path$ & Pic$ & exys ) < "" Then
bfound = True
exit for
Endif
next
if not bFound then
msgbox "No file found"
else
ActiveSheet.Pictures.Insert(Path$ & Pic$ & exts ).Select
end if

"sunilpatel" wrote in message
...
Hi how do you insert picture if you only know the filename not the
extention
Pic$ is a six digit code, but the file if it exists can be .bmp, .gif,
.jpeg , .jpg
I want to insert if exists regardless of picture type.

Please help

Thanks

sunil

I have...

If Dir(Path$ & Pic$) < "" Then
ActiveSheet.Pictures.Insert(Path$ & Pic$).Select
Endif

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default insert picture


If I knew the possible extensions, I'd just try them until I found it:

dim myExtensions as variant
dim eCtr as long
dim Pic as string
dim PicName as string
dim FoundIt as boolean
dim myPath as string

myextensions = array("bmp","gif","jpg", "jpeg")

pic = "123456"
mypath = "C:\something\"

foundit = false
for ectr = lbound(myextensions) to ubound(myextensions)
picname = mypath & pic & "." & myextensions(ectr)
if dir(picname) = "" then
'keep looking
else
exit for
foundit = true
end if
next ectr

if foundit = false then
msgbox "Not found"
else
'insert picname
end if


sunilpatel wrote:

Hi how do you insert picture if you only know the filename not the extention
Pic$ is a six digit code, but the file if it exists can be .bmp, .gif, .jpeg
, .jpg
I want to insert if exists regardless of picture type.

Please help

Thanks

sunil

I have...

If Dir(Path$ & Pic$) < "" Then
ActiveSheet.Pictures.Insert(Path$ & Pic$).Select
Endif


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
insert picture jonm Excel Programming 1 June 23rd 08 08:24 AM
how do I insert picture into cell so vlookup can return picture? ah Excel Worksheet Functions 1 May 1st 07 04:38 AM
insert a picture in to a comment but picture not save on hard disk Pablo Excel Discussion (Misc queries) 0 February 21st 07 03:48 PM
Insert Picture [email protected] Excel Programming 2 March 16th 06 12:51 AM
insert picture BillGwyer Excel Discussion (Misc queries) 1 March 4th 05 06:37 PM


All times are GMT +1. The time now is 08:59 AM.

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

About Us

"It's about Microsoft Excel"