modidying a macro for better

  • Thread starter Thread starter J_J
  • Start date Start date
J

J_J

The below code helps me to display *.jpg images in my worksheet on a
spesific locaiton with a fixed dimension after being prompth for the file
name. I need to alter my code such that
i) I can be able to display images in the *.gif, *.bmp formats as well as
*.jpg
ii) I need to have a dropdown list on my page of all the files in that
spesific directory containing the images, so that I will not need to input
the file name by typing it for each selection but only to click select from
a drop down list.
Can anyone help me alter my code? Or maybe try a new one?
Thank you in advance
J_J

'---------------------------------------
Private Sub getpicture()

Dim isim As String
Dim Resim As String
Dim InI As Integer

For InI = ActiveSheet.Shapes.Count To 2 Step -1
ActiveSheet.Shapes(InI).Delete
Next InI

isim = InputBox("Name of file")

Resim = "C:\fotolar\" & isim & ".jpg"

If Dir(Resim) = "" Then MsgBox "No Such File": End

ActiveSheet.Shapes.AddPicture(Resim, True, True, 600, 10, 100, 100).Name =
"C:\fotolar\" & isim & ".jpg"

End Sub
'-------------------------------------------
 
For filling the combobox:

With Application.FileSearch

..NewSearch
..LookIn = SPath
..FileName = "*.jpg"
..SearchSubFolders = False
..Execute

For i = 1 To .FoundFiles.Count

Call AddToComboBox(.FoundFiles(i))

Next

End With

Function AddToComboBox(Filenname)

ComboBox1.AddItem (Filename)

End function
 
Thanks for your answer Kaak,
But unfortunately I haven't used comboboxes before...:(
so I was not able to use it in conjunction with my code...
Hope someone can setup a simple guide that I can follow.
Regards
J_J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top