Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browse for pic in Excel 1

Status
Not open for further replies.

money99

Programmer
Jan 21, 2003
8
GB
Hi there.
I'm trying to make the browsing for pics in excel faster for the user. I want to use a fixed space (like the image from the Visual Basic toolbar) and then in run time when the user wants to input a pic he will double click on the image space or a button.
The problem is I dont know how to open a browser for the user to locate the pic on his/her hard disk and then load it to the dedicated space.
 
Explain in some more detail what you are trying to achieve. I think we'll be able to help.
Rob
[flowerface]
 
I'm using the Image1.Picture to load a bitmap at the image1 object. I want the user to input the path (or even better specifiy the path by browsing) and then load it(either automatically or by hitting a button). Right now I am declaring the path in cell and then trying to load a pic by using a commandbutton but I always get the Path/File access violation up to now.
 
Sounds like you have two problems:
a) how to browse for a file
b) how to assign the file to your image

The first one is fairly easy. You could use the
application.getopenfilename
method to collect the file (see the help topic for complete details). The second one we'd need to see your current code to figure out what's going wrong with the file access bit.
Rob
[flowerface]
 
The code I'm using right now is the following.


Dim picpath As String

Private Sub CommandButton1_Click()
picpath = Worksheets("Sheet1").Range("G5").Value
Image1.Picture = LoadPicture(picpath)
End Sub

Cell G5 contains the path to a bmp on my pc including the "" at beginning and end.
Thanks for the tip on the application.getopenfilename
I will look right into it.
 
I don't think you want the " at beginning and end - try removing it.
Rob
[flowerface]
 
Check This:

Private Sub Image1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim sFile As String
sFile = Application.GetOpenFilename("Image BMP (*.bmp), *.bmp")
If sFile <> &quot;&quot; Then
Image1.Picture = LoadPicture(sFile)
Else
MsgBox &quot;Failed to open the image&quot;, vbCritical
End If

End Sub

If doesn't works i could send you the Excel Workbook.
 
Hi there.
Thanks for the code. Exactly what I needed and couldn't get my head round. Nevertheless when the user opens the browser and then decides to close it or not to load a pic the whole thing crashes cause sFile is false and I need to get it safe.
 
Private Sub Image1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim sFile As String
sFile = Application.GetOpenFilename(&quot;Image BMP (*.bmp), *.bmp&quot;)
If (sFile <> &quot;&quot;) or (cancel=false) Then
Image1.Picture = LoadPicture(sFile)
Else
MsgBox &quot;Failed to open the image&quot;, vbCritical
End If

End Sub
 
oops!
Private Sub Image1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim sFile As String
sFile = Application.GetOpenFilename(&quot;Image BMP (*.bmp), *.bmp&quot;)
If (sFile <> False) Then
If (sFile <> &quot;&quot;) Then Image1.Picture = LoadPicture(sFile)
Else
MsgBox &quot;Failed to open the image&quot;, vbCritical
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top