Add an icon to an Excel userform titlebar
Posted on 2012-09-05
Is it possible to add an icon to an Excel userform titlebar? I have seen a few posts on various sites that purport to do this, for example:
'Add an icon on the titlebar
Dim hwnd As Long
Dim lngRet As Long
Dim hIcon As Long
hIcon = Sheet2.Image1.Picture.Handle
hwnd = FindWindow(vbNullString, frmMenu.Caption)
lngRet = SendMessage(hwnd, WM_SETICON, ICON_SMALL, ByVal hIcon)
lngRet = SendMessage(hwnd, WM_SETICON, ICON_BIG, ByVal hIcon)
lngRet = DrawMenuBar(hwnd)
However, when I run this sub it displays the userform but with no icon. I am running the code from a module in VB just using the 'run' button. The form is Userform2 and the picture I want to use as the icon is contained in image1 on sheet 2 of the workbook. I am using Excel 2007.
Any help would be greatly appreciated.