macro to locate picture

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Want to crteate a macro that goes to exploerer and allows me to choose any
photo by clicking on it. Not a specific photo but different ones each time I
run the macro.
Thanks
 
Use the GetOpenFileName which Displays the standard Open dialog box and gets
a file name from the user without actually opening any files. Change .txt to
the picture extension you are using such as .jpg


fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
MsgBox "Open " & fileToOpen
End If
 
Joel said:
Use the GetOpenFileName which Displays the standard Open dialog box and gets
a file name from the user without actually opening any files. Change .txt to
the picture extension you are using such as .jpg


fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
MsgBox "Open " & fileToOpen
End If
 
Hi Joel,
Thanks for the code.
I want to chenge to photo extensions so how do i write it
.GetOpenFilename (*.jpeg), *.jpeg")
This doesn't work so can you write it properly.
Thanks again
 
Iwas able to make the macro go find picture files in my picture folder. Now I
need to figure out a code that would allow me to copy and paste chosen
pictures either 1 at a time or multiple at a time and put them on my
workshhet.
Tanks for all your help. I'll send in another question if I can't figure it
out.
 
To add the picture use statement below. You can replace the hard-coded file
name with the file name return from the GetOpenFileName



Range("N16").Select
ActiveSheet.Pictures.Insert("H:\My Documents\My
Pictures\JTAG-Board.jpg"). _
Select

or

Range("N16").Select
ActiveSheet.Pictures.Insert(filetoOpen).Select
 
Joel,
What if you want ALL graphic files to show, e.g., .jpg, .gif, .bmp, .png?
How would the code be written?
Thanx.
 
fileToOpen = Application.GetOpenFilename( _
"All Graphic Files (*.jpg; *.gif; *.bmp; *.png),*.jpg;*.gif;*.bmp;*.png")

The fields are seperated with semicolons.
 
Try it this way...

Application.GetOpenFilename ("Graphic Files (*.jpg;*.gif;*.bmp;*.png)," & _
"*.jpg;*.gif;*.bmp;*.png,JPEG Files (*.jpg)," & _
"*.jpg,GIF Files (*.gif),*.gif,BMP Files (*.bmp)," & _
"*.bmp,PNG Files (*.png),*.png,All Files (*.*),*.*")
 
Maybe this layout will give you a better idea of how the argument is laid
out...

Application.GetOpenFilename _
"Graphic Files (*.jpg;*.gif;*.bmp;*.png),*.jpg;*.gif;*.bmp;*.png," & _
"JPEG Files (*.jpg),*.jpg," & _
"GIF Files (*.gif),*.gif," & _
"BMP Files (*.bmp),*.bmp," & _
"PNG Files (*.png),*.png," & _
"All Files (*.*),*.*"
 
Back
Top