Code to Insert File as Icon & Open Browse Dialog Box

J

Joyce

Hi,

I am wondering if it's possible to get users of a file to the Browse dialog
box when inserting an object as an icon.

This gets me almost there...
ExecuteExcel4Macro "INSERT.OBJECT?(,""C:\"",False,True,)"

Thank you.
 
J

Jacob Skaria

'for the second part of the question

strFile = Application.GetOpenFilename
ActiveSheet.OLEObjects.Add Filename:=strFile, Link:=False, _
DisplayAsIcon:=True, IconFileName:=strIconFile, IconIndex:=0, _
IconLabel:=strFile

'Record a macro..and edit to suit...

If this post helps click Yes
 
J

Joyce

Hello Jacob and thank you for your response.

It works beautifully. I'm wondering if there's anything I can add to do
either of the following:

1. Display only the file name and not the complete path.
2. Display the icon image of the software the file was created in (Adobe,
Word, Excel)

Thanks very much.
 
J

Jacob Skaria

Modified to display just the file name...For the icon try recording a macro
and copy paste the iconfilename from the recorded macro to the below code...

strFile = Application.GetOpenFilename
ActiveSheet.OLEObjects.Add Filename:=strFile, Link:=False, _
DisplayAsIcon:=True, IconFileName:=strIconFile, IconIndex:=0, _
IconLabel:=Mid(strFile, InStrRev(strFile, "\") + 1)

If this post helps click Yes
 
J

Joyce

Thanks Jacob. That worked beautifully.

There are two things I'm wondering now.

1. What if the file is pdf or another type of file - is there a select case
I could use?
2. What if the user's computer doesn't use the exact path to the icon file
as mine?

Thanks again for your help!
 

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

Top