Hi,
I have this sub:
Sub ShowForm(frmName)
frmName.Show
End Sub
From another sub which is attached to the OK button of a form, I pass the form name as an argument. But I get an error saying that "the macro ShowForm() can not be found."
The only way I can get the form to display is to remove the arguments and just have the parentheses.
Can I not pass arguments from macro to macro????
Here is the portion of the code attached to the OK button:
newMenuItem.Caption = "Adjust the Schedule"
newMenuItem.OnAction = "ShowForm(frmAdjustSchedule)"
The objective is to show the form when the menu item is clicked by passing the form name as an argument to the ShowForm macro. That way, I don't have to write a ShowForm() macro for each different form called by the menu items. Thus, bloating my code.
Any help would be greatly appreciated!
Here is the code for your reference:
I have this sub:
Sub ShowForm(frmName)
frmName.Show
End Sub
From another sub which is attached to the OK button of a form, I pass the form name as an argument. But I get an error saying that "the macro ShowForm() can not be found."
The only way I can get the form to display is to remove the arguments and just have the parentheses.
Can I not pass arguments from macro to macro????
Here is the portion of the code attached to the OK button:
newMenuItem.Caption = "Adjust the Schedule"
newMenuItem.OnAction = "ShowForm(frmAdjustSchedule)"
The objective is to show the form when the menu item is clicked by passing the form name as an argument to the ShowForm macro. That way, I don't have to write a ShowForm() macro for each different form called by the menu items. Thus, bloating my code.
Any help would be greatly appreciated!
Here is the code for your reference:
Code:
Sub ShowForm(frmName)
frmName.Show
End Sub
Sub Remove_Workbook_Menu()
'this removes the menu if it is present
On Error Resume Next
CommandBars("Worksheet Menu Bar").Controls("Task Blocks").Delete
On Error GoTo 0
End Sub
Sub Add_Workbook_Menu_And_Items()
Dim newMenu
Dim newMenuItem
'delete the menu if it exists by calling this subroutine
'Remove_Menu
'add a new menu to the worksheet menu. The menu is temporary and
'will disappear when Excel closes
With CommandBars("Worksheet Menu Bar")
Set newMenu = .Controls.Add( _
Type:=msoControlPopup, _
before:=.Controls("Help").Index, _
temporary:=True)
End With
'give the new menu a name
newMenu.Caption = "Task Blocks"
'add a menu item to the new menu
Set newMenuItem = newMenu.Controls.Add(Type:=msoControlButton)
'give the new menu item a name and assign a form to it
[COLOR=red]newMenuItem.Caption = "Adjust the Schedule"
newMenuItem.OnAction = "ShowForm(frmAdjustSchedule)"[/color]
'add another menu item to the new menu
Set newMenuItem = newMenu.Controls.Add(Type:=msoControlButton)
'give the new menu item a name and assign a macro to it
newMenuItem.Caption = "Add Website Project"
newMenuItem.OnAction = "Sheet3.Website"
'add another menu item to the new menu
Set newMenuItem = newMenu.Controls.Add(Type:=msoControlButton)
'give the new menu item a name and assign a macro to it
newMenuItem.Caption = "Add Printing Project"
newMenuItem.OnAction = "Sheet3.Printing"
'add another menu item to the new menu
Set newMenuItem = newMenu.Controls.Add(Type:=msoControlButton)
'give the new menu item a name and assign a macro to it
newMenuItem.Caption = "Take A Break"
newMenuItem.OnAction = "Sheet3.Break"
'add another menu item to the new menu
Set newMenuItem = newMenu.Controls.Add(Type:=msoControlButton)
'give the new menu item a name and assign a macro to it
newMenuItem.Caption = "New Task"
newMenuItem.OnAction = "Sheet3.NewTask"
End Sub