Help with custom shortcut menu

J

Jim

I am using word 2003 / win xp and have a document with a number of tables,
each of which is best served by a custom shortcut menu to facilitate entry
of information. I have gotten the shortcut menus to correctly open (this
macro is called with an index of which table the selection is in),
customized to each table, and they open the macros assigned.

All is good until case 4, in this table, I wanted to load the shortcut menu
with text captions, taken from a database, and then use one macro (ImgText)
to get the selected text and enter it into the table.

My problem is : how to I determine which of the command buttons on the
shortcut commandbar is selected so that I can pass this on to ImgText [to
eventually insert the right text (taken from a seperate database)].

I tried adding the value of "i" to the call to imgtext,
.OnAction = "ImgText" & trim(str(i)) but it doesn't recognize this as
valid. If I can tell what comand button is selected then I can pass the
index along, but I can't figure out how. It may be with an Event for the
shortcut menu (like commandbarbutton_click), but the help file is less than
helpful so I don't know exactly how to set this up or refer to the shortcut
menu. Should I dimension the menu (tableshortmenu) as a public object so I
can access it, but then what?

Any help appreciated.

Jim






Private Sub ShowTableShortMenu(ByRef TableMenu As Integer)
Dim TableShortMenu As CommandBar
Dim SplitTable, ReNumber, AddtoList, ResetTable, ShowHiddenText,
MoveActiveText, CopyText, CutText, PasteText, ShowStandard As
CommandBarControl
Set TableShortMenu = CommandBars.Add(Name:="TSM", Position:=msoBarPopup,
Temporary:=True)
Select Case TableMenu
Case 2 'subjective table

Case 3 'exam table
Set ResetTable = TableShortMenu.Controls.Add
With ResetTable
'.FaceId = CommandBars("ResetTable").Controls("Copy").ID
.Caption = "Use first selection options"
.OnAction = "Autonote.EL_Click"
End With
Set ShowHiddenText = TableShortMenu.Controls.Add
With ShowHiddenText
'.FaceId = CommandBars("ShowHiddenText").Controls("Copy").ID
.Caption = "Toggle Hidden Text"
.OnAction = "AutoNote.ToggleHidden"
End With
Set MoveActiveText = TableShortMenu.Controls.Add
With MoveActiveText
'.FaceId = CommandBars("MoveActiveTextText").Controls
("Copy").ID
.Caption = "Move Active Text to Front"
.OnAction = "AutoNote.MoveExam"
End With

Case 4 'imaging table
Dim AddCmd As CommandBarButton
Dim i As Integer
For i = 1 To 5 'this is temporary, just to show more
than 1 button
Set AddCmd = TableShortMenu.Controls.Add
With AddCmd
.Caption = i
.OnAction = "ImgText"
End With
Next i

Case 5 'Impression Table
Set SplitTable = TableShortMenu.Controls.Add
With SplitTable
'.FaceId = CommandBars("SplitTable").Controls("Copy").ID
.Caption = "Split/Unsplit the Table"
.OnAction = "AutoNote.SplitImpTable"
End With
Set ReNumber = TableShortMenu.Controls.Add
With ReNumber
'.FaceId = CommandBars("Renumber").Controls("Copy").ID
.Caption = "Renumber the Table"
.OnAction = "Autonote.OrdImpTable"
End With
Set AddtoList = TableShortMenu.Controls.Add
With AddtoList
'.FaceId = CommandBars("AddtoList").Controls("Copy").ID
.Caption = "Add to Pick List"
End With

Case 6 'Recommendation Table
Set SplitTable = TableShortMenu.Controls.Add
With SplitTable
'.FaceId = CommandBars("SplitTable").Controls("Copy").ID
.Caption = "Split/Unsplit the Table"
.OnAction = "AutoNote.SplitImpTable"
End With
Set ReNumber = TableShortMenu.Controls.Add
With ReNumber
'.FaceId = CommandBars("Renumber").Controls("Copy").ID
.Caption = "Renumber the Table"
.OnAction = "AutoNote.OrdRecTable"
End With
Set AddtoList = TableShortMenu.Controls.Add
With AddtoList
'.FaceId = CommandBars("AddtoList").Controls("Copy").ID
.Caption = "Add to Pick List"
End With

Case Else
End Select
Set CopyText = TableShortMenu.Controls.Add
With CopyText
'.FaceId = CommandBars("Standard").Controls("Copy").ID
.Caption = "Copy to the Clipboard"
End With
Set CutText = TableShortMenu.Controls.Add
With CutText
'.FaceId = CommandBars("Standard").Controls("cut").ID
.Caption = "Cut to the Clipboard"
End With
Set PasteText = TableShortMenu.Controls.Add
With PasteText
'.FaceId = CommandBars("Standard").Controls("Paste").ID
.Caption = "Paste from the Clipboard"
End With
Set ShowStandard = TableShortMenu.Controls.Add
With ShowStandard
'.FaceId = CommandBars("Standard").Controls("ShowStandard").ID
.Caption = "Show Standard Menu Choices"
.OnAction = "AutoNote.ShowStdSCMenu"
End With
TableShortMenu.ShowPopup
End Sub
 
T

Tony Jollans

CommandBars.ActionControl will give you a reference to the control that has
triggered your macro - you can then access any properties of it that you
wish.

--
Enjoy,
Tony

Jim said:
I am using word 2003 / win xp and have a document with a number of tables,
each of which is best served by a custom shortcut menu to facilitate entry
of information. I have gotten the shortcut menus to correctly open (this
macro is called with an index of which table the selection is in),
customized to each table, and they open the macros assigned.

All is good until case 4, in this table, I wanted to load the shortcut
menu
with text captions, taken from a database, and then use one macro
(ImgText)
to get the selected text and enter it into the table.

My problem is : how to I determine which of the command buttons on the
shortcut commandbar is selected so that I can pass this on to ImgText [to
eventually insert the right text (taken from a seperate database)].

I tried adding the value of "i" to the call to imgtext,
.OnAction = "ImgText" & trim(str(i)) but it doesn't recognize this as
valid. If I can tell what comand button is selected then I can pass the
index along, but I can't figure out how. It may be with an Event for the
shortcut menu (like commandbarbutton_click), but the help file is less
than
helpful so I don't know exactly how to set this up or refer to the
shortcut
menu. Should I dimension the menu (tableshortmenu) as a public object so
I
can access it, but then what?

Any help appreciated.

Jim






Private Sub ShowTableShortMenu(ByRef TableMenu As Integer)
Dim TableShortMenu As CommandBar
Dim SplitTable, ReNumber, AddtoList, ResetTable, ShowHiddenText,
MoveActiveText, CopyText, CutText, PasteText, ShowStandard As
CommandBarControl
Set TableShortMenu = CommandBars.Add(Name:="TSM", Position:=msoBarPopup,
Temporary:=True)
Select Case TableMenu
Case 2 'subjective table

Case 3 'exam table
Set ResetTable = TableShortMenu.Controls.Add
With ResetTable
'.FaceId = CommandBars("ResetTable").Controls("Copy").ID
.Caption = "Use first selection options"
.OnAction = "Autonote.EL_Click"
End With
Set ShowHiddenText = TableShortMenu.Controls.Add
With ShowHiddenText
'.FaceId = CommandBars("ShowHiddenText").Controls("Copy").ID
.Caption = "Toggle Hidden Text"
.OnAction = "AutoNote.ToggleHidden"
End With
Set MoveActiveText = TableShortMenu.Controls.Add
With MoveActiveText
'.FaceId = CommandBars("MoveActiveTextText").Controls
("Copy").ID
.Caption = "Move Active Text to Front"
.OnAction = "AutoNote.MoveExam"
End With

Case 4 'imaging table
Dim AddCmd As CommandBarButton
Dim i As Integer
For i = 1 To 5 'this is temporary, just to show more
than 1 button
Set AddCmd = TableShortMenu.Controls.Add
With AddCmd
.Caption = i
.OnAction = "ImgText"
End With
Next i

Case 5 'Impression Table
Set SplitTable = TableShortMenu.Controls.Add
With SplitTable
'.FaceId = CommandBars("SplitTable").Controls("Copy").ID
.Caption = "Split/Unsplit the Table"
.OnAction = "AutoNote.SplitImpTable"
End With
Set ReNumber = TableShortMenu.Controls.Add
With ReNumber
'.FaceId = CommandBars("Renumber").Controls("Copy").ID
.Caption = "Renumber the Table"
.OnAction = "Autonote.OrdImpTable"
End With
Set AddtoList = TableShortMenu.Controls.Add
With AddtoList
'.FaceId = CommandBars("AddtoList").Controls("Copy").ID
.Caption = "Add to Pick List"
End With

Case 6 'Recommendation Table
Set SplitTable = TableShortMenu.Controls.Add
With SplitTable
'.FaceId = CommandBars("SplitTable").Controls("Copy").ID
.Caption = "Split/Unsplit the Table"
.OnAction = "AutoNote.SplitImpTable"
End With
Set ReNumber = TableShortMenu.Controls.Add
With ReNumber
'.FaceId = CommandBars("Renumber").Controls("Copy").ID
.Caption = "Renumber the Table"
.OnAction = "AutoNote.OrdRecTable"
End With
Set AddtoList = TableShortMenu.Controls.Add
With AddtoList
'.FaceId = CommandBars("AddtoList").Controls("Copy").ID
.Caption = "Add to Pick List"
End With

Case Else
End Select
Set CopyText = TableShortMenu.Controls.Add
With CopyText
'.FaceId = CommandBars("Standard").Controls("Copy").ID
.Caption = "Copy to the Clipboard"
End With
Set CutText = TableShortMenu.Controls.Add
With CutText
'.FaceId = CommandBars("Standard").Controls("cut").ID
.Caption = "Cut to the Clipboard"
End With
Set PasteText = TableShortMenu.Controls.Add
With PasteText
'.FaceId = CommandBars("Standard").Controls("Paste").ID
.Caption = "Paste from the Clipboard"
End With
Set ShowStandard = TableShortMenu.Controls.Add
With ShowStandard
'.FaceId = CommandBars("Standard").Controls("ShowStandard").ID
.Caption = "Show Standard Menu Choices"
.OnAction = "AutoNote.ShowStdSCMenu"
End With
TableShortMenu.ShowPopup
End Sub
 
J

Jim

CommandBars.ActionControl will give you a reference to the control
that has triggered your macro - you can then access any properties of
it that you wish.

Tony,

My thanks for the rapid and absolutely helpful reply. Works great !

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top