mathiasfk
mathiasfk

Reputation: 1290

Display OLEObject as default icon

I'm trying to display a link to other Excel file from the current one. I was able to display it as a custom icon, specifying the path to the icon, but if possible I would like to display as the default Excel icon, so I don't have to send this icon file to the user.


v_sheet.OLEObjects.Add Filename:=v_fileNameToImport, Link:=True, DisplayAsIcon:=True, _
Top:=40, Left:=40, Width:=100, Height:=100, IconLabel:=v_regions(j), IconFileName:=v_iconFile, IconIndex:=0

The documentation says:

IconFileName Optional

A string that specifies the file that contains the icon to be displayed. This argument is used only if DisplayAsIcon is True. If this argument isn't specified or the file contains no icons, the default icon for the OLE class is used.

But in my case that didn't work. If I don't specify the icon it appears as a blank rectangle. What do I have to do to display this default icon?

Upvotes: 2

Views: 3394

Answers (1)

mathiasfk
mathiasfk

Reputation: 1290

It seems that you always have to specify the icon path. I've recorded a macro and added via UI and thats what I got:

Sub Macro1()
'
' Macro1 Macro
'
    Workbooks.Open Filename:= _
        "C:\Path\FileToAdd.xls"
    ActiveWindow.Visible = False
    ActiveSheet.OLEObjects.Add(Filename:= _
        "C:\Path\FileToAdd.xls.xls" _
        , Link:=True, DisplayAsIcon:=True, IconFileName:= _
        "C:\windows\Installer\{90140000-0011-0000-0000-0000000FF1CE}\xlicons.exe", _
        IconIndex:=0, IconLabel:= _
        "C:\Path\FileToAdd.xls" _
        ).Select
    Range("G8").Select
End Sub

I've found that you may simply do:

IconFileName:= "excel.exe"

It worked in mine and in others computers.

Upvotes: 2

Related Questions