Cannot change excel icon (in taskbar) with vba

我们两清 提交于 2019-12-02 14:34:23

问题


Hi I am using the following code (sorry cannot give credit, I don't know where I got it from) to change excel icon in WINDOWS' TASKBAR from the usual excel icon to an icon I have made.

But it doesn't work...only changes the small icon on the top-left corner of the application(not the taskbar)

However when I run the code in the VBA window directly, it changes the taskbar icon of the vba window to my icon !

I assume it sees the activewindow as the window currently being opened (VBA window when run directly) but when opening the book, it is not acting the same way...

I am using Windows 7

I hope someone can help....

Declare Function GetActiveWindow32 Lib "user32" Alias "GetActiveWindow" () As Integer
Declare Function SendMessage32 Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function ExtractIcon32 Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Sub ChangeApplicationIcon()


     '*****Change Icon To Suit*******
    NewIcon = ThisWorkbook.Path & "\MYICON.ICO"
     '*****************************

    Icon = ExtractIcon32(0, NewIcon, 0)
    SendMessage32 GetActiveWindow32(), &H80, 0, Icon '< 1 = big Icon
    SendMessage32 GetActiveWindow32(), &H80, 1, Icon '< 0 = small Icon

    ActiveWindow.Caption = "MY APPLICATION" 


End Sub

回答1:


The taskbar icon is a 32 pixel icon. You are setting both small and large icons to be a 16 pixel icon. Use a 32 pixel icon for ICON_BIG.



来源:https://stackoverflow.com/questions/5748968/cannot-change-excel-icon-in-taskbar-with-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!