无法使用vba更改excel图标(在任务栏中)

时间:2011-04-21 19:39:43

标签: excel vba icons taskbar

您好 我使用下面的代码(抱歉不能给予信任,我不知道从哪里得到它)将WINDOWS'TASKBAR中的excel图标从通常的excel图标更改为我已经制作的图标。

但它不起作用......只更改应用程序左上角的小图标(而不是任务栏)

但是当我直接在VBA窗口中运行代码时,它会将vba窗口的任务栏图标更改为我的图标!

我认为它将activewindow视为当前正在打开的窗口(直接运行时的VBA窗口),但是当打开书时,它的行为方式不同......

我正在使用Windows 7

我希望有人能帮忙......

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

2 个答案:

答案 0 :(得分:2)

任务栏图标是一个32像素的图标。您将小图标和大图标都设置为16像素图标。使用ICON_BIG的32像素图标。

答案 1 :(得分:0)

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