Changing the text in the top excel window bar to display your own. (Tip & Question).

I

ironmouse

In VBA I am using

Application.Caption = "my own text"
ActiveWindow.Caption = "my own text"

to change the text in the Excel Window header at the top of m
workbook. However, in the top left hand corner I still have the gree
Excel icon. what do I need to use to change the Excel icon picture t
my own, or to get rid of it completely?
Is it possible?
Tnx, ironmouse.

pls note that this is the second time I have posted this question.
Last week I posted it and had 15 views but no replies. I'm no
hopeful.....
 
M

Michel Pierron

Hi ironmouse,
In ThisWorkbook module:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" _
(ByVal hInst As Long, ByVal lpszExeFileName As String _
, ByVal nIconIndex As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer _
, ByVal lParam As Any) As Long

Private Sub Workbook_Open()
AppSetIcon False
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
AppSetIcon True
End Sub

Private Sub AppSetIcon(Optional Restore As Boolean = False)
Dim hwnd As Long, hIcon As Long
If Not Restore Then
If Dir(ThisWorkbook.Path & "\MyIcon.ico") = "" Then Exit Sub
hIcon = ExtractIcon(0, ThisWorkbook.Path & "\MyIcon.ico", 0)
End If
hwnd = FindWindow(vbNullString, Application.Caption)
SendMessage hwnd, &H80, 0, hIcon ' Small Icon
SendMessage hwnd, &H80, 1, hIcon ' Big Icon
End Sub

Regards,
MP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top