Hi everyone, have a little quandry here.
I've created a vba sub that will allow a user to insert an object (as an icon) into the selected cell. Generally these are Office or PDF files, but may also be images or text files.
The sub neatly formats the object to fit within the confines of the cell, and sets it to move/resize with the cell.
Pretty neat. User selects a target cell, and then clicks a form button that calls the macro. The standard file open dialog pops up, user selects the object, and clicks ok. Macro takes care of the rest.
OK. The problem:
If you do this manually, Excel knows how to find the proper icon for the target. PDF files get a PDF icon, word files get a word icon, etc. I just can't seem to figure out how to do that in code. If I use OLEObjects.Add and leave Iconfilename and iconindex blank I get an empty shape with no icon. The object is still there, and works ok ... just no icon.
In order to have an icon, I've resorted to using
[vba]
vFile = Application.GetOpenFilename("All Files,*.*", Title:="Select Artifact to insert")
If LCase(vFile) = "false" Then
Exit Sub
Else
lcl_a_fn = Split(vFile, "\")
lcl_vIconLabel = lcl_a_fn(UBound(lcl_a_fn))
End If
Set oNewObj = ActiveSheet.OLEObjects.Add(Filename:=vFile, _
Link:=False, DisplayAsIcon:=True, IconFileName:="explorer.exe", _
IconIndex:=1, IconLabel:=lcl_vIconLabel)
[/vba]
dows anyone know how I can determine the appropriate icon to use without knowing in advance what type of file will be selected?
I've created a vba sub that will allow a user to insert an object (as an icon) into the selected cell. Generally these are Office or PDF files, but may also be images or text files.
The sub neatly formats the object to fit within the confines of the cell, and sets it to move/resize with the cell.
Pretty neat. User selects a target cell, and then clicks a form button that calls the macro. The standard file open dialog pops up, user selects the object, and clicks ok. Macro takes care of the rest.
OK. The problem:
If you do this manually, Excel knows how to find the proper icon for the target. PDF files get a PDF icon, word files get a word icon, etc. I just can't seem to figure out how to do that in code. If I use OLEObjects.Add and leave Iconfilename and iconindex blank I get an empty shape with no icon. The object is still there, and works ok ... just no icon.
In order to have an icon, I've resorted to using
[vba]
vFile = Application.GetOpenFilename("All Files,*.*", Title:="Select Artifact to insert")
If LCase(vFile) = "false" Then
Exit Sub
Else
lcl_a_fn = Split(vFile, "\")
lcl_vIconLabel = lcl_a_fn(UBound(lcl_a_fn))
End If
Set oNewObj = ActiveSheet.OLEObjects.Add(Filename:=vFile, _
Link:=False, DisplayAsIcon:=True, IconFileName:="explorer.exe", _
IconIndex:=1, IconLabel:=lcl_vIconLabel)
[/vba]
dows anyone know how I can determine the appropriate icon to use without knowing in advance what type of file will be selected?