Share via

How To: Add OLEObjects and use the correct application version icon?

Anonymous
2015-11-11T12:22:47+00:00

Hi To Whom it may concern,

  I've read several posts on the following but I want to avoid the need of potentially having to look up the registry to ascertain the Icon file path, in that i've seen numerous posts that show IconFileName:="C:\Windows\Installer{91140000-0011-0000-0000-0000000FF1CE}\xlicons.exe" but this section "{91140000-0011-0000-0000-0000000FF1CE}" of the path could be different per user and no doubt is completely different for each office version.

  Therefore I use the following code:

ActiveSheet.OLEObjects.Add(Filename:=fd.SelectedItems(Y), Link:=bln, DisplayAsIcon:=True, IconFileName:="EXCEL.EXE", IconIndex:=0, IconLabel:=fsofl.Name)

  This works for the office product family i.e. WINWORD.EXE, POWERPNT.EXE which is great but I'd like to know how to do the same for other well known applications like Acrobat Reader which has the execution file name ACRORD32.EXE, when using the fsofl.Type (file system object file type) to determine what icon to use, this ACRORD32.EXE appears to not be recognised, hence I'd like to know where the EXCEL.EXE, WINWORD.EXE, POWERPNT.EXE are recorded and therefore work, because I'd like to add the ACRORD32.EXE and other well known applications, file extension also to that list, I've the suspicion it may have something to do with the old DOS 'path' evironment variable.

  Although if some has a routine that they are willing to share that can automatically derive the correct application icon, regardless of application version i.e. no hard coded paths so the generic routine would need to cater for the probable variance to the C:\Windows\Installer\ path, this would be very much appreciated.

  Thank you in advance.

regards

KM

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2016-09-27T16:30:09+00:00

    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?

    5 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2015-11-18T09:31:54+00:00

    Hi Mohan,

      Thank for your attempt at answering my question but regrettably you have clearly not understood correctly my original question. 

      My question, 'I'd like to knowwhere the EXCEL.EXE, WINWORD.EXE, POWERPNT.EXE are recorded' not physically stored/located on the hard drive that you have incorrectly provided. Again if you look at my VBA code, I make NO reference to their actaul file path 'ActiveSheet.OLEObjects.Add(Filename:=fd.SelectedItems(Y), Link:=bln, DisplayAsIcon:=True, IconFileName***:="EXCEL.EXE"***, IconIndex:=0, IconLabel:=fsofl.Name), I'm only referring to their (for argument sake) their 'Global' file name, hence where is the MS Office folder path recorded that allows me to just reference the application execution file name and NOT need the actual file path to be included?

      My assumption (but to be confirmed by someone in the Forum community) is that the current MS Office Version folder/file path is reco rded in the system environment variable 'PATH', the only current problem that I have is that don't have administrator rights to acess the Control Panel | System | Advance System Settings to get to the Environment Variables form, see below.

    Hope that helps to explain my question?

    0 comments No comments
  3. Anonymous
    2015-11-12T09:17:20+00:00

    Hello,

    Welcome to Microsoft Community.

    If you are looking for the location where you can find Excel.exe, Winword.exe and PowerPoint.exe for Office 2013 then you may check in the following locations:

    You will find these files in the Office15 folder in the following location:

    From Windows Explorer navigate to C:\Program Files\Microsoft Office 15\root\Office15 or C:\Program Files (x86)*Microsoft Office 15\root\Office15*

    Note: If you are on a 64 Bit computer (64 Bit Windows 8.1) then you will find the Office15 folder in the following locations.

    From your Windows Explorer: Browse to the location C:\Program Files\Microsoft Office 15\ClientX86\Root\Office15 or C:\Program Files (x86) \Microsoft Office 15\ ClientX64\Root\Office15.

    In the Office 15 folder you will find the Microsoft Office 2013 application files namely: 

    1. winword or winword.exe for Word 2013
    2. excel or excel.exe for Excel 2013
    3. powerpnt or powerpnt.exe for PowerPoint 2013
    4. onenote or onenote.exe for OneNote 2013

    For applications like Acrobat Reader and files similar to ACRORD32.EXE you may search for the files on the computer for the location of the files.

    Let us know if your need any other information.

    Thank you.

    0 comments No comments