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 !
开发者_StackOverflowI 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
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.
Declare PtrSafe Function GetActiveWindow32 Lib "user32" Alias "GetActiveWindow" () As Long
Declare PtrSafe 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 PtrSafe 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 & "\2M.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
精彩评论