I'll try to explain this as simply as possible.
I am creating an add-in with a bunch of toolbars. I want the common subs such as AddToolbartoMenu() and DeleteToolbar() to be contained in one module for the obvious simplicity in making changes. But I want the individual toolbars to each have a module with its create statement and associated macros for its menus and buttons.
My problem is that I have been VERY unsuccessful calling the CreateToolbar() subs in the individual modules. Here is what I am doing:
The CreateToolbar() sub is called from the common sub ShowToolbar(). If the toolbar doesn't exist, it is created first by calling the CreateToolbar() sub, and then made visible.
Sub ShowToolbar(Optional TOOLBAR As String, Optional MODNAME As String)
' TOOLBAR is just the name of the toolbar
' MODNAME is the name of the module it is in
' If toolbar exists toggle display
Dim ComBar As CommandBar
On Error Resume Next
Set ComBar = Application.CommandBars(TOOLBAR)
If Err.Number = 0 Then
ComBar.Visible = Not ComBar.Visible
On Error GoTo 0
Exit Sub
Else
' THIS IS WHAT'S CAUSING THE PROBLEM
Call MODNAME.CreateToolbar(TOOLBAR)
End If
On Error GoTo 0
End Sub
So the command that I'm trying to run when the workbook opens is simply
Call ShowToolbar("Navigation Toolbar", "NavigationToolbar"
However when it runs I get "Invalid Qualifier" referring to the variable MODNAME.
PLEASE, How do I call this procedure with all these variables in it? If I replace the variable name MODNAME with the text itself, it works
like this:
CALL NavigationToolbar.Createtoolbar(TOOLBAR)
But if I do this, it won't work still
MODNAME = "NavigationToolbar"
CALL MODNAME.CreateToolbar(TOOLBAR)
I don't want to change the type of MODNAME to VBCodeModule if I don't have to because of the security issues, but if it's the only way I guess I can.
Thank you all in advance
I am creating an add-in with a bunch of toolbars. I want the common subs such as AddToolbartoMenu() and DeleteToolbar() to be contained in one module for the obvious simplicity in making changes. But I want the individual toolbars to each have a module with its create statement and associated macros for its menus and buttons.
My problem is that I have been VERY unsuccessful calling the CreateToolbar() subs in the individual modules. Here is what I am doing:
The CreateToolbar() sub is called from the common sub ShowToolbar(). If the toolbar doesn't exist, it is created first by calling the CreateToolbar() sub, and then made visible.
Sub ShowToolbar(Optional TOOLBAR As String, Optional MODNAME As String)
' TOOLBAR is just the name of the toolbar
' MODNAME is the name of the module it is in
' If toolbar exists toggle display
Dim ComBar As CommandBar
On Error Resume Next
Set ComBar = Application.CommandBars(TOOLBAR)
If Err.Number = 0 Then
ComBar.Visible = Not ComBar.Visible
On Error GoTo 0
Exit Sub
Else
' THIS IS WHAT'S CAUSING THE PROBLEM
Call MODNAME.CreateToolbar(TOOLBAR)
End If
On Error GoTo 0
End Sub
So the command that I'm trying to run when the workbook opens is simply
Call ShowToolbar("Navigation Toolbar", "NavigationToolbar"
However when it runs I get "Invalid Qualifier" referring to the variable MODNAME.
PLEASE, How do I call this procedure with all these variables in it? If I replace the variable name MODNAME with the text itself, it works
CALL NavigationToolbar.Createtoolbar(TOOLBAR)
But if I do this, it won't work still
MODNAME = "NavigationToolbar"
CALL MODNAME.CreateToolbar(TOOLBAR)
I don't want to change the type of MODNAME to VBCodeModule if I don't have to because of the security issues, but if it's the only way I guess I can.
Thank you all in advance