Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Chaning The Excel Icon

Status
Not open for further replies.

DrMingle

Technical User
May 24, 2009
116
US
Can someone help...?

I'm trying to replace the Excel Icon...

Option Explicit

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 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 FindWindow Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Const WM_SETICON = &H80
Private Const ICON_SMALL = 0
Private Const ICON_BIG = 1

Sub setExcelIcon(Optional stFileName As String = "", Optional strIconIndex _
As Long = 0, Optional bSetBigIcon As Boolean = False, Optional bSetSmallIcon _
As Boolean = True)

Dim hIcon As Long
Dim hwndXLApp As Long

On Error Resume Next
hwndXLApp = FindWindow("XLMAIN", Application.Caption)

If hwndXLApp <> 0 Then
Err.Clear
If stFileName = "" Then
strIconIndex = 8000
hIcon = ExtractIcon(0, Application.Path & Application.PathSeparator & "Excel.exe", strIconIndex)
ElseIf Dir(stFileName) = "" Then
hIcon = 0
ElseIf Err.Number <> 0 Then
hIcon = 0
Else
hIcon = ExtractIcon(0, stFileName, strIconIndex)
End If

If bSetBigIcon Then SendMessage hwndXLApp, WM_SETICON, ICON_BIG, hIcon

If bSetSmallIcon Then SendMessage hwndXLApp, WM_SETICON, ICON_SMALL, hIcon
End If

End Sub

Sub Change_Icons()
setExcelIcon "C:\WINDOWS\system32\1033\dwintl.dll"
End Sub

Sub Reset_Icons()
setExcelIcon ""
End Sub
 
The code works as I imagine you expect it to for me, what do you want help with?

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Well, when I run the macro...

...nothing happens...no debug message...no icon change...

nothing...

Am I missing something...

 
Have you stepped through the code to check the hwndXLApp and hIcon values are being set correctly?

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
What icon do you need to replace? The code can only change the main (application) excel window.
It does not change file icon and workbook icons.
The workbook icons are displayed on the left of menubar (if workbook is maximised). They are also displayed in the taskbar unles the user untick this option in the options.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top