Share via

Can you insert an image (jpg) in the caption (title) portion of a userform?

Anonymous
2013-01-14T08:36:24+00:00

Hi All,

I developed a userform and would like to add a small logo, in the form of a jpeg file, to the caption (main title row) in this userform.

Does anyone know if this is possible and if it is, how to to do it?

I appreciate any support or time anyone can give to this question.

Best regards, Tim.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2013-01-15T12:54:21+00:00

OK, here is the code you need to set the icon of a userform. Change the path and filename in the code as needed.

The code goes into the userform's code 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 Long) As Long

Private Const WM_SETICON = &H80

Private Sub UserForm_Initialize()

    Dim strIconPath As String

    Dim lngIcon As Long

    Dim lnghWnd As Long

    ' Change to the path and filename of an icon file

    strIconPath = "C:\Program Files (x86)\Microsoft Office\Office14\MSN.ico"

    ' Get the icon from the source

    lngIcon = ExtractIcon(0, strIconPath, 0)

    ' Get the window handle of the userform

    lnghWnd = FindWindow("ThunderDFrame", Me.Caption)

    'Set the big (32x32) and small (16x16) icons

    SendMessage lnghWnd, WM_SETICON, True, lngIcon

    SendMessage lnghWnd, WM_SETICON, False, lngIcon

End Sub

Was this answer helpful?

4 people found this answer helpful.
0 comments No comments

16 additional answers

Sort by: Most helpful
  1. Anonymous
    2013-01-14T12:07:59+00:00

    To add to the above respondents, I think you'll need a .ico file, you can convert your .jpeg to .ico, there are several online tools for that.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-01-14T11:50:19+00:00

    Thanks Hans & Jan,

    Looks like good advice from you both -> I will need some time to investigate and absorb. Many thanks to you both for your help. Much appreciated.

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points
    2013-01-14T08:45:08+00:00

    It requires Windows API code. See for example http://www.xtremevbtalk.com/showthread.php?t=148857, or download FormFun.zip from http://www.oaltd.co.uk/excel/default.htm

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2013-01-14T08:42:55+00:00

    Hi TimFenton,

    It is possible to change the icon on the top-left corner if that is what you

    are trying to achieve.

    Download Formfun from Stephen Bullen's website:

    http://www.oaltd.co.uk/Excel/Default.htm

    Was this answer helpful?

    0 comments No comments