Excel 2019
I have user form "frmMenu" that has a number of command buttons. Each command button runs a Sub that performs actions on a certain worksheet.
This all works fine but I am having a problem when it comes to opening and closing the userfrom.
I have created a custom group on the ribbon menu and I want a sub that is run when the appropiate button on the Ribbon is clicked.
What I am trying to achieve with the code is the following logic.
If, when the button is clicked, the user form is not open, then open it, but if the user form is open then close it. Really simple right?
This sub is in its own module called "UserFrm_Menu"
In case it is related, I have a UserForm_Initialize sub that I am using to set some common elements of the command buttons which I have
put at the bottom of this post.
This sub is in the correct place (I think): Right Click on the user form > View Code > Left hand drop down = UserForm & Right hand drop down = Initialize'
Below are the three differnt methods that appear the most in searches that I have tried so far but each cause a error.'
Hopefully someone can tell me where I am going wrong.
Thanks
Compile error: Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic.
derbug hightlights
This causes Run-time error '438: Object doesen't support this property or method
Debug highlights
This also causes Run-time error '438: Object doesen't support this property or method but there is not the option to debug.
This is my UserForm Initialize sub.
I have user form "frmMenu" that has a number of command buttons. Each command button runs a Sub that performs actions on a certain worksheet.
This all works fine but I am having a problem when it comes to opening and closing the userfrom.
I have created a custom group on the ribbon menu and I want a sub that is run when the appropiate button on the Ribbon is clicked.
What I am trying to achieve with the code is the following logic.
If, when the button is clicked, the user form is not open, then open it, but if the user form is open then close it. Really simple right?
This sub is in its own module called "UserFrm_Menu"
In case it is related, I have a UserForm_Initialize sub that I am using to set some common elements of the command buttons which I have
put at the bottom of this post.
This sub is in the correct place (I think): Right Click on the user form > View Code > Left hand drop down = UserForm & Right hand drop down = Initialize'
Below are the three differnt methods that appear the most in searches that I have tried so far but each cause a error.'
Hopefully someone can tell me where I am going wrong.
Thanks
Compile error: Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic.
derbug hightlights
VBA Code:
.Visable
VBA Code:
Sub frmMediaInfoMenuOpen()
If frmMenu.Visible = True Then
frmMenu.Visible = False
Else
frmMenu.Visible = True
End If
End Sub
This causes Run-time error '438: Object doesen't support this property or method
Debug highlights
VBA Code:
If frmMenu.Visible = True Then
VBA Code:
Sub frmMediaInfoMenuOpen()
If frmMenu.Visible = True Then
frmMenu.Hide
Else
frmMenu.Show
End If
End Sub
This also causes Run-time error '438: Object doesen't support this property or method but there is not the option to debug.
VBA Code:
Sub OpenOrCloseUserForm()
On Error Resume Next
If UserForms("frmMenu").Visible = True Then
Unload Data
Else
Load Data
Data.Show
End If
End Sub
This is my UserForm Initialize sub.
VBA Code:
Private Sub UserForm_Initialize()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeName(ctrl) = "CommandButton" Then
With ctrl
.Height = 24
.Width = 282
.Left = 6
.Font.Name = "Arial"
.Font.FontStyle = "Regular"
.Font.Size = 20
End With
End If
Next ctrl
End Sub