You can test this procedure to place the module in the workbook "ThisWorkbook".
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessageA Lib "user32" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, _
ByVal lParam As Long) As Long
Private Declare Function ExtractIconA Lib "shell32.dll" _
(ByVal hInst As Long, ByVal lpszExeFileName As String, _
ByVal nIconIndex As Long) As Long
Private Sub Workbook_Activate ()
Dim File As String
Dim x As Long
'Path and filename of the icon to display
File = "C:\folder\myfile.ico"
'Check if file exists
If Dir (File) = "" Then Exit Sub
x = ExtractIconA (0, file, 0)
SendMessageA FindWindow (vbNullString, Application. Caption), _
& H80, False, x
End Sub
Private Sub Workbook_Deactivate ()
Dim File As String
Dim x As Long
File = Application. Path & "\excel.exe"
x = ExtractIconA (0, file, 0)
SendMessageA FindWindow (vbNullString, Application. Caption), _
& H80, False, x
End Sub
Bookmarks