Florent
Mechanical
- Feb 18, 2007
- 32
Hi,
If you want to add an icon in your VBA UserForm ; the same one than your button in toolbar for example.
You can add this code in UserForm's code.
Add this code at the begining of the code
Then we can add the Initialize sub or add this text in the existing one.
The result :
I hope this tip will be useful !
SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450
If you want to add an icon in your VBA UserForm ; the same one than your button in toolbar for example.
You can add this code in UserForm's code.
Add this code at the begining of the code
Code:
[COLOR=green]' first we declare some external used functions[/color]
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
Then we can add the Initialize sub or add this text in the existing one.
Code:
[COLOR=green]' Initialise UserForm with icon[/color]
Private Sub UserForm_Initialize()
Dim uFile As String
Dim x As Long
[COLOR=green] 'Full path of the picture (UNC works too) [/color]
uFile = "C:\MyPicture.bmp"
[COLOR=green]' Check if the picture file really exists, if not -> termine the sub
' Be careful if you have code behind this (maybe goto) [/color]
x = Len(Dir(uFile ))
If x = 0 Then Exit Sub
[COLOR=green]'Extract icon from picture file, and put it in the TitleBar [/color]
x = ExtractIconA(0, uFile , 0)
SendMessageA FindWindow(vbNullString, Me.Caption), &H80, False, x
End Sub
The result :
I hope this tip will be useful !
SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450