Keyboard shortcut question

  • Thread starter NoDakDame (Kathy Koppinger)
  • Start date
N

NoDakDame (Kathy Koppinger)

I suspect there is not a way to do this but I'll ask anyway.

I'm working on a large application in Word that among other things,
inserts SGML tags. I have a list of 432 standard tags that can be
inserted into the document. So far I have avoided having to hard code
the list of tags into the code by having a text file with the list of
tags. That way I can retrieve the names of the tags and pass them as
arguments to the different subroutines that insert the tags. I was
able to do this when applying tags using toolbar buttons (by setting
the parameter of the toolbar button and retrieving it in the sub that
applies the tag) and also in a user form that presents the user with a
listbox with all the tags in it.

However, I've now hit a wall. They need to be able to apply tags using
keyboard shortcuts. There are the issues I've found:

1. I can't assign a macro that takes an argument (even if it's
optional) to a keyboard shortcut.

2. I can't seem to discover which keyboard shortcut fired the
subroutine.

3. There is a CommandParameter argument when adding a keybinding,
however, it doesn't appear to do what I need. (It's used when
assigning a command such as FontSize to a shortcut to specify what
size.)

At this point the only way I can see to do this would be to create a
subroutine for each tag (all 432 of them) that would simply call the
macro that inserts the tag passing the name of the tag to it.

What is particularly annoying is that I've given the users the ability
to create custom tags on the fly for those rare cases where there is
not an appropriate standard tag. They want to be able to assign
shortcut keys to these also but if I can't use a generic macro to
insert the tag by passing the tag name, this isn't going to happen.

Thanks for your time!

KathyK
Grand Rapids, MI

--
Kathy
*****
"Use what talent you possess: the woods would be very silent if no birds sang except those that sang best."

-Henry Van Dyke (1852-1933) American scholar, educator, lyricist
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < NoDakDame (Kathy Koppinger) > écrivait :
In this message, < NoDakDame (Kathy Koppinger) > wrote:

<snip>
||
|| What is particularly annoying is that I've given the users the ability
|| to create custom tags on the fly for those rare cases where there is
|| not an appropriate standard tag. They want to be able to assign
|| shortcut keys to these also but if I can't use a generic macro to

I do not know what SGML tags are, but it seems that they are text strings
that users inserts. Why not use AutoText or AutoCorrect?

|| insert the tag by passing the tag name, this isn't going to happen.
||
|| Thanks for your time!
||
|| KathyK
|| Grand Rapids, MI
||
|| --
|| Kathy
|| *****
|| "Use what talent you possess: the woods would be very silent if no birds
sang except those that
|| sang best."
||
|| -Henry Van Dyke (1852-1933) American scholar, educator, lyricist

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
N

NoDakDame (Kathy Koppinger)

Jean-Guy Marcil said:
|| What is particularly annoying is that I've given the users the ability
|| to create custom tags on the fly for those rare cases where there is
|| not an appropriate standard tag. They want to be able to assign
|| shortcut keys to these also but if I can't use a generic macro to

I do not know what SGML tags are, but it seems that they are text strings
that users inserts. Why not use AutoText or AutoCorrect?
SGML tags are Standard General Markup Language which is the parent to
XML. I can't use AutoText because in most cases I have to insert an
open and a close tag (and sometimes the tag takes an argument)
surrounding the text the user has selected. Thus what appears is this:

{TTL}this is the text the user selected{/TTL}

Sometimes the tags appear inline as above and sometimes the tags get
their own line, so it is necessary to use a subroutine to insert all
of these. As I mentioned before I have 432 tags but only 6 subs to
insert them.

Kathy

--
Kathy
*****
"Use what talent you possess: the woods would be very silent if no birds sang except those that sang best."

-Henry Van Dyke (1852-1933) American scholar, educator, lyricist
 
K

Klaus Linke

Hi Kathy,

You could put the tags in a combo box on some toolbar. You'd only need one
macro that gets the tag that the user selected.

Some basic code to get you started below.
The combo box is put on the standard toolbar.
You can remove the combo box easily by Alt+Dragging it off with the left
mouse button.

Regards,
Klaus

Sub CreateCombo()
Dim myCBCB As CommandBarComboBox
Set myCBCB = CommandBars("Standard").Controls.Add(msoControlComboBox)
With myCBCB
.Caption = "SGML Tags"
.DescriptionText = "Select a tag"
.AddItem "Tag 1", 1
.AddItem "Tag 2", 2
.AddItem "Tag 3", 3
.DropDownWidth = 75
.ListIndex = 0
.OnAction = "TestCombo"
End With
End Sub

Sub TestCombo()
With CommandBars.ActionControl
MsgBox .List(.ListIndex), , .ListIndex
End With
End Sub




NoDakDame (Kathy Koppinger) said:
I suspect there is not a way to do this but I'll ask anyway.

I'm working on a large application in Word that among other things,
inserts SGML tags. I have a list of 432 standard tags that can be
inserted into the document. So far I have avoided having to hard code
the list of tags into the code by having a text file with the list of
tags. That way I can retrieve the names of the tags and pass them as
arguments to the different subroutines that insert the tags. I was
able to do this when applying tags using toolbar buttons (by setting
the parameter of the toolbar button and retrieving it in the sub that
applies the tag) and also in a user form that presents the user with a
listbox with all the tags in it.

However, I've now hit a wall. They need to be able to apply tags using
keyboard shortcuts. There are the issues I've found:

1. I can't assign a macro that takes an argument (even if it's
optional) to a keyboard shortcut.

2. I can't seem to discover which keyboard shortcut fired the
subroutine.

3. There is a CommandParameter argument when adding a keybinding,
however, it doesn't appear to do what I need. (It's used when
assigning a command such as FontSize to a shortcut to specify what
size.)

At this point the only way I can see to do this would be to create a
subroutine for each tag (all 432 of them) that would simply call the
macro that inserts the tag passing the name of the tag to it.

What is particularly annoying is that I've given the users the ability
to create custom tags on the fly for those rare cases where there is
not an appropriate standard tag. They want to be able to assign
shortcut keys to these also but if I can't use a generic macro to
insert the tag by passing the tag name, this isn't going to happen.

Thanks for your time!

KathyK
Grand Rapids, MI
sang except those that sang best."
 
N

NoDakDame (Kathy Koppinger)

Thanks Klaus, but this won't do it. I already have toolbar buttons for
tags the users need. I used the tag name as the parameter of the
button and the macro pulls that parameter from the ActionControl so it
can insert the correct tag.

But I also need to be able to assign keyboard shortcuts to these tags.
I've come up with a workaround. Instead of creating over 400
subroutines to handle all the tags, I've created around 60 subroutines
that are assigned to the available shortcut keys. Then I store the
name of the tag in an ini file. I built a user form to let them choose
which tag gets assigned to which shortcut which writes the information
to the ini file. All the shortcuts are set in advance in the template.
When a shortcut is used, the corresponding shortcut sub runs, checks
the ini file, if it finds something, it fires off the appropriate
macro and inserts the tag.

This allowed me to avoid hard coding the tag names into my code so
that tags may be added in the future without having to add code.

Klaus Linke said:
Hi Kathy,

You could put the tags in a combo box on some toolbar. You'd only need one
macro that gets the tag that the user selected.

Some basic code to get you started below.
The combo box is put on the standard toolbar.
You can remove the combo box easily by Alt+Dragging it off with the left
mouse button.

Regards,
Klaus

Sub CreateCombo()
Dim myCBCB As CommandBarComboBox
Set myCBCB = CommandBars("Standard").Controls.Add(msoControlComboBox)
With myCBCB
.Caption = "SGML Tags"
.DescriptionText = "Select a tag"
.AddItem "Tag 1", 1
.AddItem "Tag 2", 2
.AddItem "Tag 3", 3
.DropDownWidth = 75
.ListIndex = 0
.OnAction = "TestCombo"
End With
End Sub

Sub TestCombo()
With CommandBars.ActionControl
MsgBox .List(.ListIndex), , .ListIndex
End With
End Sub





sang except those that sang best."


--
Kathy
*****
"Use what talent you possess: the woods would be very silent if no birds sang except those that sang best."

-Henry Van Dyke (1852-1933) American scholar, educator, lyricist
 
T

Top Spin

On Fri, 02 Jul 2004 18:15:30 GMT, "NoDakDame (Kathy Koppinger)"

Kathy,

Did you ever find out if there is a way to have more than 1 keyboard
shortcut call the same macro and have the macro be able to tell which
one called it?

I would prefer that the shortcut pass an argument, but I could live
with being able to query the keys that were used.

I have several macro pairs that I would love to combone into a single
macro with a parameter since 95% of the code is identical.

Thanks
 
N

NoDakDame (Kathy Koppinger)

What I ended up doing is defining which shortcut key combinations the
users were allowed to use, for example they could assign a tag to
Ctrl+Alt+Shift+1. Then I created a subroutine for each key
combination, Sub CtrlAltShift1. I assigned each of the subs to the
appropriate key combination. I then created a dialog which lists all
the available key combinations and the list of tags to assign to them.
They select a key combination and a tag and associate them. This
information gets written to an ini file. the dialog doesn't have to do
any keybinding because that has all been done in advance.

When the user presses one of the key combinations, the associated sub
runs and checks the ini file to see what to do. So it pulls the name
of the tag and which sub inserts that particular tag and then calls
the sub passing the parameter that way.

Kathy

Top Spin said:
On Fri, 02 Jul 2004 18:15:30 GMT, "NoDakDame (Kathy Koppinger)"

Kathy,

Did you ever find out if there is a way to have more than 1 keyboard
shortcut call the same macro and have the macro be able to tell which
one called it?

I would prefer that the shortcut pass an argument, but I could live
with being able to query the keys that were used.

I have several macro pairs that I would love to combone into a single
macro with a parameter since 95% of the code is identical.

Thanks


--
Kathy
*****
"Use what talent you possess: the woods would be very silent if no birds sang except those that sang best."

-Henry Van Dyke (1852-1933) American scholar, educator, lyricist
 
T

Top Spin

What I ended up doing is defining which shortcut key combinations the
users were allowed to use, for example they could assign a tag to
Ctrl+Alt+Shift+1. Then I created a subroutine for each key
combination, Sub CtrlAltShift1. I assigned each of the subs to the
appropriate key combination. I then created a dialog which lists all
the available key combinations and the list of tags to assign to them.
They select a key combination and a tag and associate them. This
information gets written to an ini file. the dialog doesn't have to do
any keybinding because that has all been done in advance.

When the user presses one of the key combinations, the associated sub
runs and checks the ini file to see what to do. So it pulls the name
of the tag and which sub inserts that particular tag and then calls
the sub passing the parameter that way.

Yeah, that's what I did.

Did you confirm that there is no way to write one macro, assign it to
several different shortcuts, and have the macro figure out which
shortcut was used to call it when it is invoked?
 

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