J
jsl
I am trying to create a custom menu that will be (for convenience)
located After the "Help" drop-down menu. I have the following code.
The code worked like a champ when I was adding only 4 menu options
(that is, it created the "My Options" menu if it wasn't aready there
and put the first 4 options on that menu).
I was asked to add 2 more options to this menu, so I duplicated my code
for a single option twice and changed variable names, figuring if the
code had worked for the previous 4 options, it would work the for the
next 2 options I wanted to add.
However, as soon as it gets to the "set ctrl5..." line, the code barfs
with the following error:
Runtime Error -2147467259 (80004005)
Automation Error
Unspecified error
What am I doing wrong???
--jsl
******
'First, check to see if "My Options" is already on the menu bar and set
the Found flag accordingly
Set myMenuBar = CommandBars.ActiveMenuBar
MenuCount = CommandBars.ActiveMenuBar.Controls.Count
foundFlag = False
For I = 1 To MenuCount
If CommandBars.ActiveMenuBar.Controls(I).Caption = "EE Options"
Then
foundFlag = True
End If
Next I
'if we didn't find the "My Options" menu, then put it out there and put
some widgets on it
'else, exit the code because it's already there
If Not foundFlag Then
Set myMenuBar = CommandBars.ActiveMenuBar
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup,
Temporary:=True)
newMenu.Caption = "My Options"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, ID:=1)
ctrl1.Caption = " Check-Out"
ctrl1.TooltipText = "Check Out A Schedule"
ctrl1.Style = msoButtonCaption
ctrl1.OnAction = "CheckoutFile"
Set ctrl2 = newMenu.Controls.Add(Type:=msoControlButton, ID:=2)
ctrl2.Caption = "Check-In"
ctrl2.TooltipText = "Check in an Schedule"
ctrl2.Style = msoButtonCaption
ctrl2.OnAction = "CheckIn_File"
Set ctrl3 = newMenu.Controls.Add(Type:=msoControlButton, ID:=3)
ctrl3.Caption = "Copy Resource Names"
ctrl3.TooltipText = "Copy Resource Names to Formatted Field"
ctrl3.Style = msoButtonCaption
ctrl3.OnAction = "CopyResourceNamestoText11"
Set ctrl4 = newMenu.Controls.Add(Type:=msoControlButton, ID:=4)
ctrl4.Caption = "Create Successors File"
ctrl4.TooltipText = "Create Excel Successors File From Current
Project"
ctrl4.Style = msoButtonCaption
ctrl4.OnAction = "TraverseSucc"
Set ctrl5 = newMenu.Controls.Add(Type:=msoControlButton, ID:=5)
ctrl5.Caption = "Set Flag 19/20"
ctrl5.TooltipText = "Set Flag 19/20 in Current Schedule"
ctrl5.Style = msoButtonCaption
ctrl5.OnAction = "SetSomeFlags!SetFlagsForFilteredTasks"
Set ctrl6 = newMenu.Controls.Add(Type:=msoControlButton, ID:=6)
ctrl6.Caption = "Create Lag Report"
ctrl6.TooltipText = "Create Pred/Succ Lag Report"
ctrl6.Style = msoButtonCaption
ctrl6.OnAction = "CreateLagReport!MakeLagReport"
End If
located After the "Help" drop-down menu. I have the following code.
The code worked like a champ when I was adding only 4 menu options
(that is, it created the "My Options" menu if it wasn't aready there
and put the first 4 options on that menu).
I was asked to add 2 more options to this menu, so I duplicated my code
for a single option twice and changed variable names, figuring if the
code had worked for the previous 4 options, it would work the for the
next 2 options I wanted to add.
However, as soon as it gets to the "set ctrl5..." line, the code barfs
with the following error:
Runtime Error -2147467259 (80004005)
Automation Error
Unspecified error
What am I doing wrong???
--jsl
******
'First, check to see if "My Options" is already on the menu bar and set
the Found flag accordingly
Set myMenuBar = CommandBars.ActiveMenuBar
MenuCount = CommandBars.ActiveMenuBar.Controls.Count
foundFlag = False
For I = 1 To MenuCount
If CommandBars.ActiveMenuBar.Controls(I).Caption = "EE Options"
Then
foundFlag = True
End If
Next I
'if we didn't find the "My Options" menu, then put it out there and put
some widgets on it
'else, exit the code because it's already there
If Not foundFlag Then
Set myMenuBar = CommandBars.ActiveMenuBar
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup,
Temporary:=True)
newMenu.Caption = "My Options"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, ID:=1)
ctrl1.Caption = " Check-Out"
ctrl1.TooltipText = "Check Out A Schedule"
ctrl1.Style = msoButtonCaption
ctrl1.OnAction = "CheckoutFile"
Set ctrl2 = newMenu.Controls.Add(Type:=msoControlButton, ID:=2)
ctrl2.Caption = "Check-In"
ctrl2.TooltipText = "Check in an Schedule"
ctrl2.Style = msoButtonCaption
ctrl2.OnAction = "CheckIn_File"
Set ctrl3 = newMenu.Controls.Add(Type:=msoControlButton, ID:=3)
ctrl3.Caption = "Copy Resource Names"
ctrl3.TooltipText = "Copy Resource Names to Formatted Field"
ctrl3.Style = msoButtonCaption
ctrl3.OnAction = "CopyResourceNamestoText11"
Set ctrl4 = newMenu.Controls.Add(Type:=msoControlButton, ID:=4)
ctrl4.Caption = "Create Successors File"
ctrl4.TooltipText = "Create Excel Successors File From Current
Project"
ctrl4.Style = msoButtonCaption
ctrl4.OnAction = "TraverseSucc"
Set ctrl5 = newMenu.Controls.Add(Type:=msoControlButton, ID:=5)
ctrl5.Caption = "Set Flag 19/20"
ctrl5.TooltipText = "Set Flag 19/20 in Current Schedule"
ctrl5.Style = msoButtonCaption
ctrl5.OnAction = "SetSomeFlags!SetFlagsForFilteredTasks"
Set ctrl6 = newMenu.Controls.Add(Type:=msoControlButton, ID:=6)
ctrl6.Caption = "Create Lag Report"
ctrl6.TooltipText = "Create Pred/Succ Lag Report"
ctrl6.Style = msoButtonCaption
ctrl6.OnAction = "CreateLagReport!MakeLagReport"
End If