• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2612
  • Last Modified:

Add an icon to an Excel userform titlebar

Hi All

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:

Sub AddIcon()
'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)
End Sub

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.

Regards

Terry
0
Terrygordon
Asked:
Terrygordon
  • 4
  • 2
1 Solution
 
Martin LissRetired ProgrammerCommented:
Can you attach your workbook?
0
 
TerrygordonAuthor Commented:
Hi Martin

I don't actually have the workbook. I just created a simple test workbook with a blank userform and an image on sheet2 to see if the code would work before using it on the main project. I've now tried recreating it and I'm getting a "method or data member not found" error on Image1.
0
 
Rory ArchibaldCommented:
Try this one
Book5.xls
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
TerrygordonAuthor Commented:
Hi Rory

This seems to work fine with the icon you have placed in the image, but not for jpg or gif formats. Can I assume therefore that the picture has to be a specific type of file and, if so, which type? I have tried using an icon file created with an icon creator software called icoFX, which is recognised as an icon file by the image import dialog, but when I click to open it I get an "Invalid picture" message.

Regards

Terry
0
 
Rory ArchibaldCommented:
It needs to be a valid icon file I believe (.ico).
0
 
TerrygordonAuthor Commented:
Thanks Rory. I will have a play with some different formats. The code itself works great.

Regards

Terry
0
 
TerrygordonAuthor Commented:
Just for reference if anyone else is using this code, the icon file has to be 24 bits or less. 48 x 48 true color seems to work best in terms of resolution and most icon editors will let you choose this resolution. Anything above 24 will not be imported into the image box.

Regards

Terry
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now