XML for Comment Button

L

ldjarmin

Alright, so here's what I'm looking at.

I'm making a custom tab on the Ribbon/Fluent UI in Word 2007. I've got that
part down. It'll be populated with a series of buttons and/or drop down
boxes, each of which is set to insert a prescripted comment into the document
at where the cursor is. How do I do this? I know how to make a button which
inserts some text into the document, but not how to make the button (or
alternatively choosing an option from a drop down list or whatever) insert a
comment.


Also, on a related note, is there a way to make this user customizable? By
that I mean, have like a Word document or Excel file that has all the names
of the comments and the comment text and the user can change the text of a
comment or title?

Thanks!
 
T

Tony Jollans

This has nothing directly to do with the ribbon. Your button that inserts
text has a callback that can run arbitrary VBA code - just make it insert a
comment instead ...

Selection.Comments.Add Selection.Range, "The Moon's a Balloon"

You can make the whole thing as sophisticated as you like - it just depends
how much effort you want to put into it. A lookup to another Word document
or an Excel table or a text file or registry entries or ... is certainly
possible. I don't know off the top of my head how to fill in a dropdown in
the ribbon but it must be possible - or your ribbon button could bring up a
userform from which a choice could be made or maintenance of the cross
reference list could be done or ... the world's your lobster.
 
G

Greg Maxey

This has nothing directly to do with the ribbon. Your button that inserts
text has a callback that can run arbitrary VBA code - just make it insert a
comment instead ...

    Selection.Comments.Add Selection.Range, "The Moon's a Balloon"

You can make the whole thing as sophisticated as you like - it just depends
how much effort you want to put into it. A lookup to another Word document
or an Excel table or a text file or registry entries or ... is certainly
possible. I don't know off the top of my head how to fill in a dropdown in
the ribbon but it must be possible - or your ribbon button could bring up a
userform from which a choice could be made or maintenance of the cross
reference list could be done or ... the world's your lobster.

--
Enjoy,
Tony









- Show quoted text -

I am not sure that I understand you complete objective, but continuing
with what Tony suggested, you only need the XML to define the Tab, the
Group, and ID the dropdown. You need to have an OnAction macro
defined for the DropDown. The XML might look something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="Onload">
<ribbon>
<tabs>
<tab id="CustomTab" label="My Tab">
<group id="SampleGroup" label="Sample Group">
<dropDown id="DD1" label="My DropDownBox" getItemCount=
"GetItemCount" getItemLabel="GetItemLabel" onAction="MyDDMacro">
</dropDown>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

Then in the VBA project module you can define how many dropdown items
there needs to be, what their labels are, and what happens when each
one is clicked:

Option Explicit
Public myRibbon As IRibbonUI

Sub Onload(ribbon As IRibbonUI)
Set myRibbon = ribbon
End Sub

Sub MyDDMacro(ByVal control As IRibbonControl, selectedId As String,
selectedIndex As Integer)
Select Case selectedIndex
Case Is = 0
Selection.Comments.Add Selection.Range, "The Moon's a Balloon"
Case Is = 1
Selection.Comments.Add Selection.Range, "Tony is a master of the
array"
Case Is = 2
Selection.Comments.Add Selection.Range, "NG courtesy cop need not
reply"
End Select
End Sub

Sub GetItemLabel(ByVal control As IRibbonControl, Index As Integer,
ByRef label)
Select Case control.ID
Case "DD1"
Select Case Index
Case Is = 0
label = "Moon comment"
Case Is = 1
label = "Tony Comment"
Case Is = 2
label = "Courtesy cop comment"
End Select
End Select
End Sub

Sub GetItemCount(ByVal control As IRibbonControl, ByRef count)
Select Case control.ID
Case "DD1"
count = 3
Case Else
'Do Nothing
End Select
End Sub
 

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