无法使用vba更改excel图标(在任务栏中) [英] Cannot change excel icon (in taskbar) with vba

查看:524
本文介绍了无法使用vba更改excel图标(在任务栏中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


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

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)

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

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

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

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我正在使用Windows 7

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


推荐答案

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

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.

这篇关于无法使用vba更改excel图标(在任务栏中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆