|
-
Apr 9th, 2004, 06:48 PM
#1
Thread Starter
Lively Member
Excel - program icon
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.
-----
#VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP
I miss my VIC 20.
Never should have upgraded to my commodore 64. ...
-
Apr 12th, 2004, 07:01 PM
#2
Lively Member
this is the code i had.. which worked for me:
VB Code:
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!
"Through every dark night there's a brighter day, so no matter how hard it get, put your chest out and keep your head up, and handle it"
-
Apr 13th, 2004, 06:31 PM
#3
Thread Starter
Lively Member
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?
-----
#VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP
I miss my VIC 20.
Never should have upgraded to my commodore 64. ...
-
Apr 13th, 2004, 11:02 PM
#4
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.
VB Code:
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 Sub
HTH
Last edited by RobDog888; Apr 13th, 2004 at 11:11 PM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 14th, 2004, 04:32 PM
#5
Thread Starter
Lively Member
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?
-----
#VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP
I miss my VIC 20.
Never should have upgraded to my commodore 64. ...
-
Apr 15th, 2004, 10:19 AM
#6
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 15th, 2004, 10:35 AM
#7
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 15th, 2004, 01:39 PM
#8
Lively Member
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.
yeah.. same here .. i got it working perfectly on my office XP..on windows 2k...
"Through every dark night there's a brighter day, so no matter how hard it get, put your chest out and keep your head up, and handle it"
-
Apr 17th, 2004, 06:40 PM
#9
Thread Starter
Lively Member
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.
-----
#VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP
I miss my VIC 20.
Never should have upgraded to my commodore 64. ...
-
Apr 17th, 2004, 07:02 PM
#10
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 4th, 2019, 04:26 PM
#11
New Member
Re: Excel - program icon
 Originally Posted by amer7862000
this is the code i had.. which worked for me:
VB Code:
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! 
Code worked great!!
How do I change the icon size?
-
Aug 5th, 2019, 01:44 PM
#12
Re: Excel - program icon
Hello and Welcome to the Forums.
Im glad the code works for you. However it would be best to create a new thread and link to this one as to not bump old threads.
Thanks
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|