我是vba语言的新手,最近我必须编写一个Excel addIn来做一些自动工作。我的addIn有一个userform,我的addIn的用户可能同时打开多个工作簿并在这些工作簿之间切换,这需要打开的用户窗体坚持活动的工作簿。我的尝试是: *
Private WithEvents App As Application
Private m_userform1 As UserForm1
Private Sub App_WorkbookActivate(ByVal Wb As Workbook)
MsgBox Wb.Name
Set m_userform = UserForms.Add("UserForm1")
m_userform.Show vbModeless
End Sub
Private Sub App_WorkbookDeactivate(ByVal Wb As Workbook)
MsgBox Wb.Name
Unload m_userform
Set m_userform = Nothing
End Sub
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
'MsgBox "test app_workbookOpen"
End Sub
Private Sub Workbook_Open()
Application.OnKey "^e", "Commander"
Set App = Application
End Sub
通过这个实现,当我打开一个工作簿时,一切运行正常,但随后打开另一个工作簿,出现错误消息5,这是从
引发的Set m_userform = UserForms.Add("UserForm1")
有人可以给我一些关于这个问题的见解吗?很多人赞赏!