Hello Casedias,
This macro will change the icon for Excel 2003 using an icon from a file. This may require some changes if you are using this with excel 2007 or 2010. If you are not changing the Excel icon then this macro will be need to changed to work with any Windows window.
Copy and paste this code into a new VBA module in your workbook's VBA project.
'Written: March 29, 2011
'Author: Leith Ross
'Constants
Const IMAGE_ICON As Long = &H1
Const WM_SETICON As Long = &H80
Const ICON_BIG As Long = &H1
'Constants for Load Image's fuLoad Parameter (Load Resource)
Const LR_DEFAULTCOLOR As Long = &H0
Const LR_MONOCHROME As Long = &H1
Const LR_COLOR As Long = &H2
Const LR_COPYRETURNORG As Long = &H4
Const LR_COPYDELETEORG As Long = &H8
Const LR_LOADFROMFILE As Long = &H10
Const LR_LOADTRANSPARENT As Long = &H20
Const LR_DEFAULTSIZE As Long = &H40
Const LR_VGACOLOR As Long = &H80
Const LR_LOADMAP3DCOLORS As Long = &H1000
Const LR_CREATEDIBSECTION As Long = &H2000
Const LR_COPYFROMRESOURCE As Long = &H4000
Const LR_SHARED As Long = &H8000
'Returns an Icon from a File (.ico)
Private Declare Function LoadImage _
Lib "user32.dll" Alias "LoadImageA" _
(ByVal hInst As Long, _
ByVal lpsz As String, _
ByVal uType As Long, _
ByVal cxDesired As Long, _
ByVal cyDesired As Long, _
ByVal fuLoad As Long) _
As Long
'Direct System what to do with the Window
Private Declare Function SendMessage _
Lib "user32.dll" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Long) _
As Long
'Redraw the Icons on the Window's Title Bar
Private Declare Function DrawMenuBar _
Lib "user32.dll" _
(ByVal hWnd As Long) _
As Long
Public Function ChangeExcelIcon(ByVal Icon_File_Path As String)
Dim hWnd As Long
Dim hIcon As Long
Dim LoadMask As Long
hWnd = Application.hWnd
LoadMask = LR_LOADFROMFILE Or LR_DEFAULTSIZE Or LR_SHARED
hIcon = LoadImage(0&, Icon_File_Path, IMAGE_ICON, 32, 32, LoadMask)
Call SendMessage(hWnd, WM_SETICON, ICON_BIG, ByVal hIcon)
Call DrawMenuBar(hWnd)
End Function
Example of Using th Macro
Sub IconTest()
ChangeExcelIcon "C:\Documents and Settings\Admin.ADMINS\My Documents\Properties 16.ico"
End Sub
Bookmarks