5

I kept a userform control button in my worksheet to fire up a macro, which in turn shows a user form, In the form I wish to display the opened files in checkboxes(using the Workbooks collection).I wish to run a macro that performs action for the user selected files only.

So for the button in my worksheet, I have assigned the following macro

Private Sub Button2_Click()

    Load MyForm

    MyForm.Show

End Sub 

At first I kept the below code in the module where my macro sub is there.Since it's not working, I right clicked on user form and selected view code and kept the below code there.But still it's showing the same static designed user form, not the dynamic.I kept breakpoint at both load Myform and MYform.Show() and I stepped through code.It never went into intialize or activate method at all.

Private Sub MyForm_Activate()
  'for checking the whether this method is called or not I am trying to change caption
  MyForm.LabelSelectFile.Caption = "dhfdfldkfldzjf;zdfkz;d"

  Dim mymyWorkBook As Workbook
  For Each mymyWorkBook In Workbooks
     'code for creating checkbox based on the file name displayed by the workbook collection      
  Next mymyWorkBook
End Sub

I can't understand why that event is not getting triggered.Please help me to overcome this.Thanks in advance

4

1 回答 1

13

即使表单的名称是MyForm,您仍然需要使用userform.

'~~> in your worksheet
Private Sub Button2_Click()
    MyForm.Show
End Sub

'~~> In the userform code area
Private Sub UserForm_Initialize()
    '~~> Your code here
End Sub

或者

Private Sub UserForm_Activate()

End Sub

最好的办法是始终从下拉列表中选择事件,而不是输入它

在此处输入图像描述

于 2013-10-16T11:33:52.713 回答