PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Excel - program icon-VBForums
Results 1 to 12 of 12

Thread: Excel - program icon

  1. #1

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126

    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. ...

  2. #2
    Lively Member amer7862000's Avatar
    Join Date
    Apr 2004
    Location
    North West, UK
    Posts
    94
    this is the code i had.. which worked for me:

    VB Code:
    1. Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
    2.         ByVal lpWindowName As String) As Long
    3.  
    4. Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    5.         ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
    6.  
    7. Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, _
    8.         ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
    9.  
    10. Const WM_SETICON = &H80
    11.  
    12. Sub SetExcelIcon()
    13.     Dim lngXLHwnd As Long, lngIcon As Long, strIconPath As String
    14.  
    15.     'Use whichever icon file you want to use here
    16.     strIconPath = "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Flags\FLGUK.ICO"
    17.     lngXLHwnd = FindWindow("XLMAIN", Application.Caption)
    18.  
    19.     lngIcon = ExtractIcon(0, strIconPath, 0)
    20.  
    21.     SendMessage lngXLHwnd, WM_SETICON, False, lngIcon
    22.  
    23. 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"

  3. #3

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    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. ...

  4. #4
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,695
    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:
    1. Option Explicit
    2.  
    3. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
    4. ByVal lpWindowName As String) As Long
    5.  
    6. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
    7. ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
    8.  
    9. Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, _
    10. ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
    11.  
    12. Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
    13.  
    14. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, _
    15. ByVal nMaxCount As Long) As Long
    16.  
    17. Private Const WM_SETICON = &H80
    18. Private Const GW_HWNDNEXT = 2
    19.  
    20. Private Sub SetExcelIcon()
    21. 'CHANGE ALL EXCEL APP WINDOWS THE A DIFFERRENT ICON
    22.     Dim lngXLHwnd As Long, lngIcon As Long, strIconPath As String, sCls As String, lRetVal As Long
    23.        
    24.     'Use whichever icon file you want to use here
    25.     strIconPath = "C:\Program Files\Microsoft Visual Studio\Common\FLGUK.ICO"
    26.     lngXLHwnd = FindWindow("XLMAIN", vbNullString)
    27.     Do While lngXLHwnd <> 0
    28.         sCls = Space(255)
    29.         lRetVal = GetClassName(lngXLHwnd, sCls, 255)
    30.         If lRetVal <> 0 Then
    31.             If Left(sCls, lRetVal) = "XLMAIN" Then
    32.                 lngIcon = ExtractIcon(0, strIconPath, 0)
    33.                 lRetVal = SendMessage(lngXLHwnd, WM_SETICON, ByVal 0&, ByVal lngIcon)
    34.             End If
    35.         End If
    36.         lngXLHwnd = GetWindow(lngXLHwnd, GW_HWNDNEXT)
    37.     Loop
    38.  
    39. End Sub
    40.  
    41. Private Sub Workbook_Open()
    42.     Call SetExcelIcon
    43. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    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. ...

  6. #6
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,695
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,695
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  8. #8
    Lively Member amer7862000's Avatar
    Join Date
    Apr 2004
    Location
    North West, UK
    Posts
    94
    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"

  9. #9

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    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. ...

  10. #10
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,695
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  11. #11
    New Member
    Join Date
    Aug 2019
    Posts
    2

    Re: Excel - program icon

    Quote Originally Posted by amer7862000 View Post
    this is the code i had.. which worked for me:

    VB Code:
    1. Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
    2.         ByVal lpWindowName As String) As Long
    3.  
    4. Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    5.         ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
    6.  
    7. Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, _
    8.         ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
    9.  
    10. Const WM_SETICON = &H80
    11.  
    12. Sub SetExcelIcon()
    13.     Dim lngXLHwnd As Long, lngIcon As Long, strIconPath As String
    14.  
    15.     'Use whichever icon file you want to use here
    16.     strIconPath = "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Flags\FLGUK.ICO"
    17.     lngXLHwnd = FindWindow("XLMAIN", Application.Caption)
    18.  
    19.     lngIcon = ExtractIcon(0, strIconPath, 0)
    20.  
    21.     SendMessage lngXLHwnd, WM_SETICON, False, lngIcon
    22.  
    23. End Sub

    hope this helps!
    Code worked great!!

    How do I change the icon size?

  12. #12
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,695

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Featured


Click Here to Expand Forum to Full Width