UserForm OnAction

  • Thread starter Thread starter Maria
  • Start date Start date
M

Maria

Hi,

I have created a userdefined CommandBar with a button.
From this button I would like to start a UserForm.

Usually I use something like the following Codeline to
call a Prozedure:
..OnAction = MyCode

I wanted to do the same with the UserForm:
..OnAction = frmMyUserForm

Unfortunately it doesn't work.
Is it possible to allocate a UserForm?

Thank you,
Maria
 
Hi Tom,

unfortunately it doesn't work.

You can try it:

Sub test()
Dim cmb As CommandBar
Dim cmbp As CommandBarPopup

Set cmb = Application.CommandBars("Standard")
Set cmbp = cmb.Controls.Add(Type:=msoControlPopup)

cmbp.Caption = "test"

With cmbp.Controls.Add
.BeginGroup = True
.Caption = "test"
.FaceId = 231
.OnAction = frmMyUserForm.Show
End With
End Sub

Maria
 
That isn't what I suggest. I suggested creating a macro that shows the
userform. then assigning that macro to the onaction property

Sub test()
Dim cmb As CommandBar
Dim cmbp As CommandBarPopup

Set cmb = Application.CommandBars("Standard")
Set cmbp = cmb.Controls.Add(Type:=msoControlPopup)

cmbp.Caption = "test"

With cmbp.Controls.Add
.BeginGroup = True
.Caption = "test"
.FaceId = 231
.OnAction = "Showform"
End With
End Sub

Sub Showform()
frmMyUserForm.Show
End Sub

sorry if my response appeared to indicate anything other than the above.
 
But Tom didn't suggest that.

He suggested something like:

Sub test()
Dim cmb As CommandBar
Dim cmbp As CommandBarPopup

Set cmb = Application.CommandBars("Standard")
Set cmbp = cmb.Controls.Add(Type:=msoControlPopup)

cmbp.Caption = "test"

With cmbp.Controls.Add
.BeginGroup = True
.Caption = "test"
.FaceId = 231
.OnAction = "MyCode"
End With
End Sub

Sub Mycode()
frmMyUserForm.Show
End sub
 
oh ... that's a way! :-)
Thank you.
Maria
-----Original Message-----
That isn't what I suggest. I suggested creating a macro that shows the
userform. then assigning that macro to the onaction property

Sub test()
Dim cmb As CommandBar
Dim cmbp As CommandBarPopup

Set cmb = Application.CommandBars("Standard")
Set cmbp = cmb.Controls.Add(Type:=msoControlPopup)

cmbp.Caption = "test"

With cmbp.Controls.Add
.BeginGroup = True
.Caption = "test"
.FaceId = 231
.OnAction = "Showform"
End With
End Sub

Sub Showform()
frmMyUserForm.Show
End Sub

sorry if my response appeared to indicate anything other than the above.

--
Regards,
Tom Ogilvy




.
 
Back
Top