-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateMenus.bas
84 lines (68 loc) · 2.95 KB
/
CreateMenus.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Attribute VB_Name = "CreateMenus"
Option Explicit
'*******************************************************************
'Sub/Func : sbCreateMenuItems
'Author : James Rivera
'Purpose : Create the menu item entry points for this tool.
'Arguments : None.
'Returns : None.
'Comments : Uses menu item strings from StringTable.bas
'*******************************************************************
'History : 04/02/2003 (James Rivera) - Created.
' : 12/18/2012 (Kenichi Koyama) - modified
'*******************************************************************
Public Sub sbCreateMenuItems()
Const CALLER = "sbCreateMenuItems"
On Error GoTo sbCreateMenuItems_ErrorHandler
Dim cbCtl As Office.CommandBarControl
Dim cbBtn As Office.CommandBarButton
Dim cbPopup As Office.CommandBarPopup
' First delete any old ones if they exist.
sbRemoveMenuItems
With Application.CommandBars(1).Controls
' Create top-level "Comment Tool" menu item.
Set cbCtl = .Add(msoControlPopup, , , .Count + 1, False)
cbCtl.Caption = MENU_EXPORTTOOLS
cbCtl.Tag = MENU_EXPORTTOOLS
cbCtl.BeginGroup = True
' Get a handle to the control for top-level menu item.
Set cbPopup = cbCtl
' Create submenu for Comments creation dialog.
Set cbBtn = cbPopup.Controls.Add(msoControlButton, , , cbPopup.Controls.Count + 1, False)
With cbBtn
.OnAction = "ExportVBA.sbShowForm"
.Caption = MENU_EXPORTTOOLS_VBACOMPONENTS
.Tag = MENU_EXPORTTOOLS_VBACOMPONENTS
End With
End With
Exit Sub
sbCreateMenuItems_ErrorHandler:
MsgBox "ERROR " & Hex(Err.Number) & ": " & Err.Description, vbCritical, CALLER
Exit Sub
End Sub 'sbCreateMenuItems
'*******************************************************************
'Sub/Func : sbRemoveMenuItems
'Author : James Rivera
'Purpose : Remove the menu item entry points for this tool.
'Arguments : None.
'Returns : None.
'Comments : Uses menu item strings from StringTable.bas
'*******************************************************************
'History : 04/02/2003 (James Rivera) - Created.
' : 12/18/2012 (Kenichi Koyama) - modified
'*******************************************************************
Public Sub sbRemoveMenuItems()
Const CALLER = "sbRemoveMenuItems"
On Error GoTo sbRemoveMenuItems_ErrorHandler
Dim cbCtl As Office.CommandBarControl
' Delete any instances of the top-level menu if they exist.
Set cbCtl = Application.CommandBars.FindControl(msoControlPopup, , MENU_EXPORTTOOLS)
While Not (cbCtl Is Nothing)
cbCtl.Delete
Set cbCtl = Application.CommandBars.FindControl(msoControlPopup, , MENU_EXPORTTOOLS)
Wend
Exit Sub
sbRemoveMenuItems_ErrorHandler:
MsgBox "ERROR " & Hex(Err.Number) & ": " & Err.Description, vbCritical, CALLER
Resume Next
End Sub 'sbRemoveMenuItems