打开另一个工作簿时,更改Excel图标不起作用 [英] Changing Excel Icon doesn't work when another workbook is opened

查看:247
本文介绍了打开另一个工作簿时,更改Excel图标不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码,可以很好地将Excel图标更改为我自己的图标.

I am using the following code, which nicely changes the Excel icon to my own icon.

就我自己打开工作簿而言,它是完美的,但是一旦打开另一个工作簿,该代码似乎不再起作用. 它仅在完全关闭Excel的情况下才有效,然后使用代码打开工作簿. 一旦我打开另一个工作簿,从一个工作簿更改为另一个工作簿,等等,它将不再起作用.

It works perfectly as far as I open the workbook by itself BUT, as soon as another workbook is already opened, the code doesn't seem to have any effect any longer. It only works if Excel is completely closed, then I open the workbook with the code. As soon as I open another workbook, change from one workbook to another, etc, it not longer works.

我正在使用Windows 7,Excel 2007.

I am using Windows 7, Excel 2007.

我希望有人可以提供帮助. 谢谢

I hope someone can help. Thanks

Private Sub Workbook_Open()    
    changeXLIcon "D:/myBOOK/IQS.ico"
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
    changeXLIcon "D:/myBOOK/IQS.ico"
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
    changeXLIcon "Excel.exe"
End Sub


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

Public Sub changeXLIcon(iconname As String)

    Dim Icon&


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


End Sub

推荐答案

我猜想,问题出在Excel正在运行多个进程,而您只为当前Window设置了图标.不仅应该调用GetActiveWindow32(),还应尝试检索名为EXCEL.EXE的所有进程的列表,然后使用SendMessage32将所有进程的图标更改为它们各自的句柄.

I'd guess that the problems stems from Excel having several processes running while you only set the icon for the current Window. Instead of just calling GetActiveWindow32() you should try to retrieve a list of all processes named EXCEL.EXE and then change the icon on all of them using SendMessage32 to their respective handle.

这篇关于打开另一个工作簿时,更改Excel图标不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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