将图标添加到Excel用户表单

时间:2015-06-27 23:03:08

标签: vba excel-vba excel

我试图使用此代码向我的项目中的任何用户窗体添加图标..但我总是收到此错误:"对象变量或With block变量未设置& #34;

如何解决此问题,为什么会出现此错误?

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _
lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" _
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As _
Long) As Long

Public 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

Public Const WM_SETICON = &H80

Public Sub SetUserformIcon(ByVal UFName As String, ByVal strIconPath As _
String)

  Dim lngIcon, lnghWnd As Long
  Dim UForm As UserForm

  lngIcon = ExtractIcon(0, strIconPath, 0)
  UForm.Name = UFName
  lnghWnd = FindWindow("ThunderDFrame", UForm.Caption)
  SendMessage lnghWnd, WM_SETICON, True, lngIcon
  SendMessage lnghWnd, WM_SETICON, False, lngIcon
End Sub

Private Sub UserForm_Initialize()
  SetUserformIcon "AAA_Form", ThisWorkbook.Path _
  & "\Icons\MyIcon.ico"
End Sub

0 个答案:

没有答案