I have created 7 List Template Macros which I have added to a drop-down menu in a toolbar. I was wondering if it was possible to include a checkmark next to the last selected item from the menu so the user is aware of the current list template in use. Thanx in advance for any help… trish
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Custom Menu Showing Selected (Word XP)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Custom Menu Showing Selected (Word XP)
- This topic has 15 replies, 3 voices, and was last updated 21 years, 11 months ago.
AuthorTopicWStkrokosh
AskWoody LoungerMay 1, 2003 at 7:47 pm #386850Viewing 0 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerMay 1, 2003 at 9:53 pm #672803The checkmark next to a menu item is governed by its State property. If State = msoButtonDown, there is a checkmark, and if State = msoButtonUp, there isn’t.
You’d have to add code to your macros that sets the State for each of the menu items. How to do that depends on how you organized your code. -
WStkrokosh
AskWoody LoungerMay 30, 2003 at 8:23 pm #681223Hi Hans… well I ended up creating a toolbar from code – oh my gosh – I have figured out how to do almost everything, with the exception of this .state = msobuttonup/down/mixed! Cannot believe that this feature has me pickled… I’ve included the code that creates the toolbar which is an AutoOpen event on the template (so when the template attaches, the toolbar is created). The toolbar has customized images on it and I’m creating a ‘dummy’ toolbar to create these images from files (new XP IPictureDisp – member of Stdole library) and the using .copyface and .pasteface to change image (I could not figure out how to include in the commandbarbutton statement)… STILL LEARNING… Anyhow, back to the .state – what I’m looking for is IF the user selects the item on the dropdown menu, I want a checkmark placed next to the item. IF the user selects another menu item, I want the checkmark to move and appear next to the last item that they have selected. I’m also confused if this state is run here or in a different location (as a Function??). I’ve attached the code… If you have any suggestions/ideas with regard to my code, I would love to hear… thanx in advance… trish
-
WSHansV
AskWoody LoungerMay 30, 2003 at 9:36 pm #6812351. I don’t understand why you need a dummy toolbar to get the images. Since you’ve worked out how to get them, you might as well apply that code to the Numbering toolbar immediately.
2. Your code suggests that you don’t have Option Explicit – there are undeclared variables in the code. May I strongly recommend that you turn this on? It’ll save you a lot of grief. Select Tools | Options… in the Visual Basic Editor, and check Require Declarations (or something similar, I don’t know the exact caption in English.)
3. You may want to set the CustomizationContext to ThisDocument, because otherwise, the new commandbar will be stored in Normal.dot (unless that is your intention, of course.)
4. I would set the Tag property for each of the items in the Schemes popup to a unique value; it can be a number (1, 2, 3, …), or a descriptive string. Then, you can write one procedure that acts as OnAction argument for all items. The item clicked by the user is CommandBars.ActionControl; you can inspect its Tag property. Loop through the items of the popup and set the State to msoButtonUp, then set it to msoButtonDown for the ActionControl. To perform the desired action for each item, use a Select Case statement.
Assume that you set the OnAction property for each item of the popup to “SchemeAction”, and that you have assigned numeric Tags. The code for SchemeAction could look like this:
Sub SchemeAction()
Dim oCmdBar As Office.CommandBar
Dim oCmdBarButton As Office.CommandBarButton
Dim oCmdBarPop As Office.CommandBarPopup
Dim oCmdBarSubPop As Office.CommandBarButtonSet oCmdBar = Application.CommandBars(“Numbering”)
Set oCmdBarPop = oCmdBar.Controls(“Schemes”)‘ Set State
For Each oCmdBarSubPop In oCmdBarPop.Controls
oCmdBarSubPop.State = msoButtonUp
Next oCmdBarSubPop
CommandBars.ActionControl.State = msoButtonDown‘ Action to perform
Select Case CommandBars.ActionControl.Tag
Case 1
‘ Code for first item
Case 2
‘ Code for second item
‘ etc.
End Select
End Sub -
WStkrokosh
AskWoody LoungerJune 2, 2003 at 9:11 pm #681811Hi Hans… thanx over and over again for all your assistance to me!!!
With regard to your feedback:
1. For some stupid reason (I’m tooo inexperienced to figure it out) I cannot set the picture property under the commandbarbutton… I get this error msg: Run-time error ‘-2147467259(80004005); Method ‘Picture’ of object’_CommandBarButton failed.
I have changed the code to read as follows, and continue to have the same error msg that I had last week:Dim objPicture As IPictureDisp
Set objPicture1 = stdole.StdFunctions.LoadPicture(“c:atk imagesrestartno.bmp”)
Set oCmdBarButton = oCmdBar.Controls.Add(msoControlButton, Before:=11)
With oCmdBarButton
.Picture = objPicture1
.Visible = True
.Caption = “Restart Numbering”
.BeginGroup = True
.OnAction = “RestartNo”
.TooltipText = “Restart Numbering”
End With
I found an KB Article ( http://support.microsoft.com/?kbid=286460%5B/url%5D ) that explains that the IPictureDisp interface cannot be marshalled across process boundaries… I have no clue what this means… So if I create the dummy bar and copyface/pasteface it works fine? Can you explain what I am doing wrong or what this means?
2. I did include the Option Explicit as you suggested… I read up on it and was unaware of it’s importance. The only problem is that the commandbar runs on an AutoOpen event and Option Explicit is stored under general declarations. Should I be doing something different?
3. I did include the CustomizationContext.Active Document as you suggested… I do not want the toolbar to be stored in Normal… only when the template attaches.
4. I did get my msobuttonup/down state working using your suggested Select Case statement (not used before)… I ended up performing a ‘call’ procedure under the Select Case to run the macro for the selected numbering scheme:Select Case CommandBars.ActionControl.Tag
Case “SchemeArticleNo1”
Call SchemeArticleNo1
Is this correct?Once again Hans, thank you for all your help… I would be lost without you!
-
WSHansV
AskWoody LoungerJune 2, 2003 at 9:50 pm #681819Hello Trish,
The reason you can’t set the picture property for the buttons on the Numbering toolbar is because you set .Protection = msoBarNoCustomize for this toolbar immediately after creating it, so you can’t customize the pictures. You should set the Protection property after making all other changes. Then, you can move all the code for setting pictures down, and you won’t need the dummy toolbar any more.
Requiring declarations in Tools | Options… only sets Option Explicit in all new modules. You’ll have to set it yourself at the top of all existing modules.
Your case statement (the part of it that you posted) looks OK.
-
WStkrokosh
AskWoody LoungerJune 2, 2003 at 10:40 pm #681827Hi Hans… thanx for getting back to me so soon! I should have known better with the NoCustomization… I already ran into another problem with that… Thank you for pointing this out to me
.
Sorry, I’m not getting this Option Explicit… I did type it in at the top of my module, but it gives me the following error: Compile Error: invalid inside procedure.
Private Sub Document_Open()
‘Creates the Numbering toolbar required to run
‘the Schemes module of this template
‘Recorded by Trish Krokosh, May 30, 2003Option Explicit
Dim oCmdBar As Office.CommandBar
Dim oCmdBarButton As Office.CommandBarButton
Dim oCmdBarPop As Office.CommandBarPopup
Dim oCmdBarSubPop As Office.CommandBarButton
Dim objPicture As IPictureDispThe procedure I want is Document_Open() or AutoOpen (). The examples which I have seen with Option Explicit change it from a Document_Open event to a General Declaration. How do I declare both?
-
WSHansV
AskWoody LoungerJune 2, 2003 at 11:00 pm #681832Hi Trish,
Option Explicit is a module-level setting. You must put it at the very top of a module, before all declarations, subs and functions, not within a sub or function. What it does is require you to declare all variables explicitly throughout the module. If you don’t have Option Explicit, the following is valid:
Sub DoSomething
lngNumber = 123
…A new variable lngNumber will be created on the fly and given the value 123. Great, I can hear you think, what’s wrong with that? Well, for instance that you are not protected against typos:
Sub DoSomething
lngNumber = 123
…
MsgBox lngNunber
…You made a small mistake while typing, and VBA will create a new variable lngNunber for you. Since it has not been assigned a value explicitly, it is 0, so MsgBox displays 0 instead of 123. There is no error message to warn you of this. In more complicated code, you might not notice a mistake like this, and trust the outcome.
Now, suppose you have Option Explicit at the top of the module. If you don’t declare lngNumber, VBA will complain that is is unknown. So you insert Dim lngNumber As Long:
Sub DoSomething
Dim lngNumber As Long
lngNumber = 123
…
MsgBox lngNunber
…VBA will still complain because lngNunber is not defined. So you are forced to recognize the typo.
In your case, you should have something like this:
Option Explicit
Private Sub Document_Open()
‘Creates the Numbering toolbar required to run
‘the Schemes module of this template
‘Recorded by Trish Krokosh, May 30, 2003Dim oCmdBar As Office.CommandBar
Dim oCmdBarButton As Office.CommandBarButton
Dim oCmdBarPop As Office.CommandBarPopup
Dim oCmdBarSubPop As Office.CommandBarButton
Dim objPicture As IPictureDisp -
WStkrokosh
AskWoody LoungerJune 3, 2003 at 2:15 pm #682167I understand much better now… thank you very much Hans…
… After your explanation, I’m thinking that this should be placed above all my code, since I did not have the Option, Require Variable Declaration turned on… this is what I will do… I don’t think that I’ve told you lately that I love you… here you go…
and
!!! I’m finished with this module and going on to the next… accessing an Access query to populate a template! Wish me luck… you’ll probably hear from me again! Cheers! trish
-
WStkrokosh
AskWoody LoungerJune 3, 2003 at 4:19 pm #682207I’m beginning to feel like a pest… I made all the changes and tested this morning…
1. I included Option Explicit at the top of the code and it placed a line underneath (to me indicating a new procedure…is this how it should be acting?
2. I’m having a problem with the msobuttonup/down, the state is not changing when a document is new/opened. I need the state to initially be set to msobuttonup in all documents… can you help?? Here’s the code which you so graciously helped me with:Sub SchemeAction()
Dim oCmdBar As Office.CommandBar
Dim oCmdBarButton As Office.CommandBarButton
Dim oCmdBarPop As Office.CommandBarPopup
Dim oCmdBarSubPop As Office.CommandBarButton
Dim objPicture As stdole.IPictureDispSet oCmdBar = Application.CommandBars(“Numbering”)
Set oCmdBarPop = oCmdBar.Controls(“Schemes”)‘Set State
For Each oCmdBarSubPop In oCmdBarPop.Controls
oCmdBarSubPop.State = msoButtonUp
Next oCmdBarSubPop
CommandBars.ActionControl.State = msoButtonDownSelect Case CommandBars.ActionControl.Tag
Case “SchemeArticleNo1”
Call SchemeArticleNo1
Case “SchemeArticleNo2”
Call SchemeArticleNo2
Case “SchemeFFN1”
Call SchemeFFN1
Case “SchemeFFN2”
Call SchemeFFN2
Case “SchemeFFN3”
Call SchemeFFN3
Case “SchemeFFN4”
Call SchemeFFN4
Case “SchemeStandard”
Call SchemeStandard
End Select
End Sub -
WSHansV
AskWoody LoungerJune 3, 2003 at 5:46 pm #682234Hi Trish,
1. By default, VBA will display a line after the general declaration section and after each function and procedure in a module. If you don’t like it, select Tools | Options… (in the Visual Basic Editor); the bottommost check box in the Editor tab determines whether you get these lines.
2. You can add code to set the state to “up” in the Document_New and Document_Open (or AutoNew and AutoOpen) macros. You can call a common procedure from both (note that this is identical to a part of SchemeAction; you could call StatesUp from there too):
Sub StatesUp()
Dim oCmdBar As Office.CommandBar
Dim oCmdBarButton As Office.CommandBarButton
Dim oCmdBarPop As Office.CommandBarPopup
Dim oCmdBarSubPop As Office.CommandBarButtonSet oCmdBar = Application.CommandBars(“Numbering”)
Set oCmdBarPop = oCmdBar.Controls(“Schemes”)‘Set State
For Each oCmdBarSubPop In oCmdBarPop.Controls
oCmdBarSubPop.State = msoButtonUp
Next oCmdBarSubPop
End Sub -
WSHansV
AskWoody LoungerJune 3, 2003 at 5:50 pm #682235Additional remark: if you want the “state” of the buttons to change automatically when you switch back and forth from document to document, it becomes a lot more complicated. You’d have to store the states of all buttons in the document, and write application-level event handlers. This is not trivial, see for example Selectively disable menu option (Word 97/2000).
-
WStkrokosh
AskWoody LoungerJune 3, 2003 at 7:19 pm #682263You’re right…
OK, I had to rethink this requirement… I have included the .state up code in Document_Close event which will clean up the checkmark when the user closes. The problem now is if the user selects a scheme, I don’t want the state to change in that document, even if they close it and reopen it. If they open a new document I want the state to change to msobuttonup and if they open an existing document but it has never had a scheme applied, I want the state to change to msobuttonup. The checkmark is not that important and I’m beginning to feel a little overwhelmed – thank god for Hans!
The checkmark’s purpose is to identify to the user the last listtemplate (scheme) which was selected in the document (for document sharing, shortcut key, etc.)… so… what I’m thinking is just writing more code with a new button on the toolbar or you helped me create a msgbox which lists the current templates in the activedocument – is it possible to include more text to identify the ‘active scheme’?
Sub ListSchemes()
‘Brings a message box with a list of current schemes being
‘used in documentDim strList As String
Dim strActList as String
Dim lst As ListTemplatestrList = “Schemes in Current Document:”
For Each lst In ActiveDocument.ListTemplates
strList = strList & vbCrLf & lst.Name
Next lst
StrActList = “Active Scheme in Current Document:”
?MsgBox strList
MsgBox strActList End SubWhat are your thoughts or suggestions in this regard… Thanx so very much for all your help Hans…
-
WSHansV
AskWoody Lounger -
WSGary Frieder
AskWoody LoungerJune 3, 2003 at 8:54 pm #682292Trish,
Haven’t followed this thread closely, nor seen the code you’re using for creating the named list templates, but it sounds like it would be hard to identify the “active list template” in a document, upon opening the document – if a document has more more than one list template in use somewhere in its contents, how do you define what is the “active” one?
If by active list template, you mean the last one interactively used in that document by a previous user, perhaps you can store the name of that list template using a docvariable (Hans’ favored method) or a custom document property (my favored method). This would involve just adding a line of code to store this value, in the code you’re using to apply the list template.
Then in Document_Open, you have code that looks up the stored value – any chance of doing something like that?Gary
-
WStkrokosh
AskWoody LoungerJune 3, 2003 at 10:02 pm #682317Gary… welcome to my nightmare!
… Poor Hans… I feel bad for bugging him so much… in your statement: If by active list template, you mean the last one interactively used in that document by a previous user YES… THIS IS WHAT I’M LOOKING FOR! Then you continue… perhaps you can store the name of that list template using a docvariable (Hans’ favored method) or a custom document property (my favored method). This would involve just adding a line of code to store this value, in the code you’re using to apply the list template. Then in Document_Open, you have code that looks up the stored value – any chance of doing something like that? OK – Sounds great… if you read through the thread, you will find that I am a beginner at all this! I am going to read up on docvariables and custom document property and then try to figure out… you will probably hear back from me… thanx for the pointer in the right direction!
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
hibernate activation
by
e_belmont
18 minutes ago -
Red Hat Enterprise Linux 10 with AI assistant
by
Alex5723
36 minutes ago -
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
3 hours, 41 minutes ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
3 hours, 43 minutes ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
6 hours, 52 minutes ago -
Out of band for Windows 10
by
Susan Bradley
8 hours, 26 minutes ago -
Giving UniGetUi a test run.
by
RetiredGeek
15 hours, 23 minutes ago -
Windows 11 Insider Preview Build 26100.4188 (24H2) released to Release Preview
by
joep517
23 hours ago -
Microsoft is now putting quantum encryption in Windows builds
by
Alex5723
20 hours, 59 minutes ago -
Auto Time Zone Adjustment
by
wadeer
1 day, 3 hours ago -
To download Win 11 Pro 23H2 ISO.
by
Eddieloh
1 day, 1 hour ago -
Manage your browsing experience with Edge
by
Mary Branscombe
5 hours, 45 minutes ago -
Fewer vulnerabilities, larger updates
by
Susan Bradley
16 hours, 41 minutes ago -
Hobbies — There’s free software for that!
by
Deanna McElveen
35 minutes ago -
Apps included with macOS
by
Will Fastie
20 hours, 36 minutes ago -
Xfinity home internet
by
MrJimPhelps
20 hours, 31 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
20 hours, 29 minutes ago -
Debian 12.11 released
by
Alex5723
2 days ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
2 days, 4 hours ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
1 day, 7 hours ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
22 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
2 days, 21 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
2 days, 11 hours ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
9 hours, 21 minutes ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
2 days, 16 hours ago -
Some advice for managing my wireless internet gateway
by
LHiggins
1 day, 23 hours ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
1 day, 1 hour ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
3 days, 9 hours ago -
Sometimes I wonder about these bots
by
Susan Bradley
21 hours, 30 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
2 days, 19 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.