A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Just in case anyone else comes across this question that I had, I managed to resolve the issue in an alternative way, in that within the shell32.dll there is a handy library that goes by the name of 'FindExecutableA' that returns the execution application file name for a 'full' file path/name provided.
I use this method to determine what the appropriate application is in order to get at the appropriate application icon, so in my VBA code I use:
Set obj = ActiveSheet.OLEObjects.Add(Filename:=fd.SelectedItems(Y), Link:=bln, DisplayAsIcon:=True, IconFileName:=strAPP_EXE, IconIndex:=0, IconLabel:=fsofl.ShortName)
where strAPP_EXE = fncGET_APP_EXE(fsofl.Name)
fncGET_APP_EXE refers to the public function
Public Function fncGET_APP_EXE(sFile As String) As String
Dim Z As Integer, str As String
str = String(260, 32)
Z = FindAppExe(sFile, vbNullString, str) ' Find the associated application path
If Z > 32 Then
fncGET_APP_EXE = Left$(str, InStr(str, Chr$(0)) - 1) ' Return the application path
Else
fncGET_APP_EXE = "PACKAGER.EXE" ' or if no file type association is found, use the default packager icon.
End If
End Function
FindAppExe referes to the declared library
#If VBA7 Then
Public Declare PtrSafe Function FindAppExe Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As LongPtr
#Else
Public Declare Function FindAppExe Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
#End If
Take note if you don't care for a 'default' package then just set the IconFileName to the 'full' file path, it does the same but for any selected files that have no associated application like a .DAT file for instance, then you embedded file object will just show a white box with a label.
Set obj = ActiveSheet.OLEObjects.Add(Filename:=fd.SelectedItems(Y), Link:=bln, DisplayAsIcon:=True, **IconFileName:=**fd.SelectedItems(Y), IconIndex:=0, IconLabel:=fsofl.ShortName).
Hope that helps?