0

How can I hide the excel application and add a system tray icon for the userform? I saw that there are previous code for this but I cannot make it work. Can anyone help me with this problem. Thank you everyone

This is the code that i'm looking at and I'm having a hard time applying this code. An error always comes up every time I run the macro

Compile Error: Type Mismatch

and it come from this part of the code

Private Sub AddIcon()
'Add an icon on the titlebar
    Dim hWnd As Long
    Dim lngRet As Long
    Dim hIcon As Long
    hIcon = Sheet1.Image1.Picture.Handle
    hWnd = FindWindow(vbNullString, Me.Caption)
    lngRet = SendMessage(hWnd, WM_SETICON, ICON_SMALL, ByVal hIcon)
    lngRet = SendMessage(hWnd, WM_SETICON, ICON_BIG, ByVal hIcon)
    lngRet = DrawMenuBar(hWnd)
End Sub

the highlighted part was this hWnd = FindWindow(vbNullString, Me.Caption)

Compile Error

braX
  • 11,506
  • 5
  • 20
  • 33
Jeremy
  • 1
  • 3
  • If you're trying to use some code you saw online, it would be useful to include it or at least link to it, and describe exactly what problem you're having with it. – Tim Williams Nov 19 '18 at 02:48
  • @TimWilliams I edited my question sorry for that. – Jeremy Nov 19 '18 at 03:07
  • Since you're using 64-bit did you make the necessary updates? Eg. see https://codekabinett.com/rdumps.php?Lang=2&targetDoc=windows-api-declaration-vba-64-bit – Tim Williams Nov 19 '18 at 03:26
  • @TimWilliams yes there's an actual code from the link above for 64 bit. Now my problem is every time I run the code a Compiler error always shows up. (See image above) and I can't find a way to resolve this issue. – Jeremy Nov 19 '18 at 05:09
  • It would help to include the relevant API declaration in your question. For example does your `FindWindow` function return a `LongPtr` or a `Long`? – Tim Williams Nov 19 '18 at 05:30
  • I am assuming you are using this [code](https://www.tek-tips.com/viewthread.cfm?qid=1693252) right? If so you cannot parse a nullstring to the window that is looking for – Sgdva Mar 28 '20 at 19:20

0 Answers0