PDA

Click to See Complete Forum and Search --> : Excel - program icon


TheFIDDLER
Apr 9th, 2004, 06:48 PM
Anyone have a method to change the default Excel Icon? The small X on the taskbar.

I have seen posts on this before. But have never found a version of code that works for all versions of Excel.

amer7862000
Apr 12th, 2004, 07:01 PM
this is the code i had.. which worked for me:


Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long

Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, _
ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long

Const WM_SETICON = &H80

Sub SetExcelIcon()
Dim lngXLHwnd As Long, lngIcon As Long, strIconPath As String

'Use whichever icon file you want to use here
strIconPath = "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Flags\FLGUK.ICO"
lngXLHwnd = FindWindow("XLMAIN", Application.Caption)

lngIcon = ExtractIcon(0, strIconPath, 0)

SendMessage lngXLHwnd, WM_SETICON, False, lngIcon

End Sub


hope this helps! :bigyello:

TheFIDDLER
Apr 13th, 2004, 06:31 PM
Thank you for your wonderful bit of code.. I have seen similar code to this before, just never been able to get it to work.

This one doesn't work me in either Excel 97 or Excel 02.

Actually - doesn't have any noticeable effect.

What I am missing? Anyone else have any luck with this?

RobDog888
Apr 13th, 2004, 11:02 PM
This works on 2003 and 2000. I know this is for that program of
yours so I made it change all Excel icons.

My Office XP system is turned off ot work so I couldnt remotely
test it.
Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long

Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, _
ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long

Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long

Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long

Private Const WM_SETICON = &H80
Private Const GW_HWNDNEXT = 2

Private Sub SetExcelIcon()
'CHANGE ALL EXCEL APP WINDOWS THE A DIFFERRENT ICON
Dim lngXLHwnd As Long, lngIcon As Long, strIconPath As String, sCls As String, lRetVal As Long

'Use whichever icon file you want to use here
strIconPath = "C:\Program Files\Microsoft Visual Studio\Common\FLGUK.ICO"
lngXLHwnd = FindWindow("XLMAIN", vbNullString)
Do While lngXLHwnd <> 0
sCls = Space(255)
lRetVal = GetClassName(lngXLHwnd, sCls, 255)
If lRetVal <> 0 Then
If Left(sCls, lRetVal) = "XLMAIN" Then
lngIcon = ExtractIcon(0, strIconPath, 0)
lRetVal = SendMessage(lngXLHwnd, WM_SETICON, ByVal 0&, ByVal lngIcon)
End If
End If
lngXLHwnd = GetWindow(lngXLHwnd, GW_HWNDNEXT)
Loop

End Sub

Private Sub Workbook_Open()
Call SetExcelIcon
End SubHTH

TheFIDDLER
Apr 14th, 2004, 04:32 PM
Ok, I must be missing something very obvious.
I tried to copy/paste both examples of code, and tried it in both the main workbook module, and then in standalone excel modules, and even tried the function as stored in a class module. I run the code, both via the macro itself, and by accessing via the auto_open subroutine in case it needs to initialize during the opening of a workbook.

I do tweak the code a bit to reference an icon file I have. I even made it super simple as a path c:\test.ico I use a valid ico since I can change other programs to it.

I get nothing. Just tested both back in 2003 and 97.
I get no code errors, just no visible results.

Since this is an API call, is there something else I need to be looking at?

RobDog888
Apr 15th, 2004, 10:19 AM
What is you os? I am going to boot up my other system which
has XP/Office XP and test it out. Sorry for the delay, but I was out
yesterday. Will let you know what I find out.

RobDog888
Apr 15th, 2004, 10:35 AM
Works great om my Windows XP/Office XP system. The only
version I can not test is Office 97. It even worked on 2000
Terminal Server/Office 2000.

:confused:

amer7862000
Apr 15th, 2004, 01:39 PM
Originally posted by RobDog888
Works great om my Windows XP/Office XP system. The only
version I can not test is Office 97. It even worked on 2000
Terminal Server/Office 2000.

:confused:

yeah.. same here .. i got it working perfectly on my office XP..on windows 2k...

TheFIDDLER
Apr 17th, 2004, 06:40 PM
Knew if was something simple that I was missing -
I was referencing a corrupt icon file.

OK - new question - but still within the same thread.

How do I code a reference to the little green tree that is found
within the shell32.dll file. And does this file and image exist in different versions of windows.

RobDog888
Apr 17th, 2004, 07:02 PM
You need to use the ExtractIcon API with the correct path to the
shell32.dll which will depend on the os platform. The last
parameter is the index number for the little green tree icon. Some
trial and error will tell you what its index number is.

HTH