-
kdock
AskWoody PlusHi Hans,
I want to present the user with a list of names (with other bits of info). They can choose one or more and insert information into the document. The template in which this listbox resides also gathers a lot of other information to ultimately compile the document. The WP table also presents this same office with names for their WP templates — it’s used in a lot of ways. This is why I would like to keep the document in WP. It gives the client one place to change info and one file to distribute. This is why I’m trying to make it work.
I have pulled the WP table document into Word and run various macros on it to clean it up. No reason I couldn’t then save it.
But the bottom line is that I have had no luck populating a listbox data from anywhere. I had code from the MVP site (populating a listbox from a named range in Excel) that gives me an error message that it can’t find the object I’m trying to use. There’s clearly something I’m missing — a reference, perhaps — that is keeping me from successfully getting the data into the listbox.
I hope I’ve explained it a little better. Thanks for your response.
Kim -
kdock
AskWoody PlusHi Magella,
I have done this kind of thing from template to template; you can iterate through all commandbars and styles with a For each statement, but I specified the macro projects by name — seems to me I had problems trying to copy any and all projects.
Further, some anti-virus programs find this kind of thing *extremely* alarming and might not even permit loading the template with the code in it, let alone stop you from using it without disabling auto-detect.
I have to agree that the template/document connection is a valuable one and trying to do an end run around it may lead to disappointment — are you trying to make your documents as portable as possible?
Kim
-
kdock
AskWoody PlusBut what a wonderful idea!!
It certainly gets your attention, and it’s a very stable feature in Word… I can easily add that to the code that inserts the comment in the first place.
I think I’ll do a little testing and see what response I get from the more sensitive types.
Thanks!
K -
kdock
AskWoody PlusHi J,
Oh, I don’t really care about the initials. It’s the highlighting that doesn’t print that I want! Ironically enough, you can change the style of the Comment Text that appears in the Reviewing Pane. What good that does I’m not sure, except that you can enlarge the text if you have a very high resolution monitor.
Thanks for applying your brain power to this.
Kim -
kdock
AskWoody PlusWell,
Done all that. We used comments as an easy way to pass along important information about a document — they were meant to be read only and the highlighting that didn’t print was a visible cue that some special information existed. The brackets of the current feature are barely visible, even though the hovering works the same.
Showing the ballons doesn’t work because they print and would need to be acted upon before printing — either delete altogether, which defeats the purpose of the informational comment in the first place, or toggle the balloon off, print, toggle back on. This requires ‘way ‘way too much thinking and again defeats the purpose of an easy-to-use feature. MSoft just made it much harder, is all.
Oh well —
, indeed.
Thanks very much,
Kim -
kdock
AskWoody PlusMost excellent!
And thanks for posting his reply.
K
-
kdock
AskWoody PlusHi Trish… The responses in this thread suggesting you copy the style into the document are probably pretty sound. However, knowing what the progression is for this whole process would be helpful. For example, if there’s a possibility that someone with a newer document has somehow edited BodyText in their document would lessen the value of automatically copying the style over it.
If, on the other hand, your company has strict rules about formatting and no one should be messing with BodyText, well…
In regard to your original question, and off the top of my head, I suggest that your macro check for the existence of the BodyText style first and if it doesn’t exist, create it. You seemed to say this had occurred to you, but you followed it with “however, a user may select more than one ‘scheme’ (list template) in their document” — how does this impact searching for your BodyText style?
I *think* what you want to do can be done (that is, if I’m clear on what you want to do), but you may need to build a couple more modules to call in order to separate your error handling code.
Kim
-
kdock
AskWoody Plus(Edited by HansV to activate link to post – see Help 19)
Hi Trish, I’m going to post my response to the active thread (post 256454). Hopefully, it will be helpful… Kim
-
kdock
AskWoody PlusOK, it sounds like all you need is a mechanism to launch your code. There are a couple of ways to approach this.
First, you can create a document new event that will run whenever you create a new document from your template. The way to do this is to open your template, then open VBA and find your template in the project explorer (usually on the left top of the window). You should see below the name the “Microsoft Word Objects.” If the folder is closed, click the + next to it to show the “ThisDocument” object. If you double click on it, you should open a blank code window.
In the code window, type
Private Sub Document_New()
**type or copy your code here**
End Sub
When you File|New to create a document based on your Subpoena template, the document_new event “fires” as VBA recognizes that you are creating a new document. Your code will run automatically and the document that results should have the results of your input boxes (since it works from running the code from the VBA editor).
If you want the code to run every time the document is opened, your must put your code in a similar sub routine:
Private Sub Document_Open()
**your code here**
End Sub
This code will run EVERY time you open the document. It is probably not what you want, so unless there’s an insurmountable reason that the input boxes capture data to an already existing document rather than while the new document is being created, then this isn’t a very good solution. You can Cancel the input boxes, but if you have more than a half dozen, anyone using the documents will become tired of that.
Because the code is not actually in the document, but really in the template associated with the document, you can associate the Subpoena with another template (like normal.dot) and the prompting will stop. This seems like an unnecessary step, unless there’s something about your document that I don’t know. Do you add information over several editing sessions?
The last way to run the code is “on demand” by the user. Leave your code where it is in the template (it is in the template and not in normal, right?). Add a button to the toolbar that runs the code. Do that this way:
Open the Subpoena template. Click Tools|Customize. Click on the Commands tab and in the Categories list, scroll down to “Macros” and click. To the right, you’ll see all the macros that are currently available. Make certain that the “Save in” drop down list at the bottom of the window shows the name of your template.
**We’re going to save the button to run the code ONLY in the template that has the code. It will only appear when the Subpoena template is active. I like to have a separate toolbar for this kind of thing saved in normal.dot. The buttons come and go as templates are loaded and unloaded from the environment. The bottom line is that they should only appear when it is appropriate to use them.**)
OK, now scroll down the macros listed on the right of the dialog box until you find your input box macro. Click and drag it to the toolbar of your choice. You can right click and make the button look better — check the options on the context sensitive help.
Then, you will be able to run your code by clicking on the button. You should, by the way, be able to go to Tools|Macro|Macros (or Alt-F8) and be able to find your code in the list of Macro names. You should also be able to run it from there.
Note that running a macro or assigning it to a toolbar button requires that your code be public. The two examples I gave above use the word “Private” because only VBA has to find and use them. In order for a user to find and run the code, you need to have your sub look like this:
Sub MySubRoutine()
**code**
End Sub-or-
Public Sub MySubRoutine()
**code**
End SubThere are other interesting rules about code visibility that you’ll address as you become more proficient. I learned a LOT of code from deconstructing the code that came from Microsoft (though much of it is a lot more than you’ll ever need). I have also made good use of program help (make sure you have the VBA help installed, I think it is not the default to do so). Use the Knowledge Base at microsoft.com and there are several books out there (I think a thread ran last week in this forum on the subject).
If this doesn’t make sense, please let me know. If it does — good!
Kim
-
kdock
AskWoody PlusOooops. Then you know all about Word. I assumed you were a WP expert. But you seem to have inherited the Word programming . It sounded as if you worked in a law office; straddling the word processing fence is a common practice for a firm.
I’m a little confused about your process, though. Your template has the Subpoena form and input boxes. Have you placed the code in a document event such as DocumentNew? That way the input boxes code will run automatically when you create a new document from the template. You can also put them in a DocumentOpen event so they will run whenever the document is opened (this can get very annoying, however, as it will happen EVERY time). You can also put a toolbar button on a new or standard toolbar that will run the sub whenever the user chooses.
Does any of this do what you want? If so, I can elaborate…
Kim
-
kdock
AskWoody PlusHi Gwynne,
OK, this is just my two cents…
I started working in VBA when my firm decided to make the switch from WordPerfect to Word just before Office 97 came out. It was necessary to jump into VBA immediately, because the hundreds of forms and macros that the whole firm relied on were essential to their practice.
Here’s where the two cents come in: Remember that you don’t always have to use macros, templates and wizards to do everything in Word. It has its own strengths and weaknesses. You might be able to accomplish a lot of what WP did with a macro using the regular features of Word like autotext and fields. My problem was I knew how to program but I didn’t know so much about Word. (You know that old saying — if the only tool you have is a hammer, every problem looks like a nail.)
As you’re learning VBA, you will naturally learn Word. Still, you can’t learn Word soon enough — you’ll save yourself a lot of work. And believe me, there will still be plenty of programming to do.
Kim
-
kdock
AskWoody PlusI wish I knew a little more about the circumstances of this macro; I might have just a little more advice
However, on the face of it, it seems as if you need an error handler.
This code checks for the style using Set (see below). Setting a value to an object that doesn’t exist produces an error which you can capture and use to your benefit.
Sub DoesNewStyleExist(fdummy As Boolean) ' Check for style named "StyX" ' If not there, goes to error handler Dim StyleExist As Object Dim S As Integer Dim Style2 On Error GoTo StyleNotThere Set StyleExist = ActiveDocument.Styles("Sty1") If StyleExist.NameLocal = ("Sty1") Then End If Exit Sub StyleNotThere: ' Your code to create the styles and link to list template End Sub
BTW (and forgive me if you already knew) “(fdummy As Boolean)” keeps a macro from appearing in Word’s list of macros.
Does this help?
Kim
-
kdock
AskWoody PlusApril 21, 2003 at 3:20 pm in reply to: Need to list lines from ComboBox (English/Word97/SR2) #670034Instead of using an “equal to” can you use a “less than or equal to” and qualify by the line number rather than the text of the item?
Just a thought off the top of my head.
Kim
-
kdock
AskWoody PlusHere’s a little more info from my experience with numbering, for what it’s worth. You can address a specific panel in the List Templates through VBA code:
ActiveDocument.Styles(“Heading 1”).LinkToListTemplate ListTemplate:= _
ListGalleries(wdOutlineNumberGallery).ListTemplates(5), ListLevelNumber:=1In this code, I linked Heading 1 style to ListTemplate number 5 (the sixth panel, counting from 0 in the upper left). However, there is danger in this. If you reuse this code with frequency, that panel can become corrupted. If you hightlight that panel and click reset, you will clear the corruption. (Or maybe it’s just confusion.)
The List Templates panel is specific to your computer. You could run the above code on one computer with no problem, but on another computer, the exact code might return an error because that particular panel was corrupted due to overuse. When you open a document, information about the numbering is loaded into one of the List Templates panels on your computer as a temp area in which to display and interpret the numbering from the document.
MSoft thought users could set up their own numbering schemes here (which works OK if you are the only one using the computer OR the document AND you don’t have more than 7 schemes). But it is far more dynamic than that. A friend and I once passed the same Word 97 document back and forth, making minor changes to the numbering scheme and watched as it used panel 7, then panel 6, then panel 5… until each panel in the List Templates dialog was overwritten (except 0), then started over with 7 again. If I had laboriously set up numbering schemes, they would have been gone with the wind — until I opened a document with one of my schemes in it. Then the next available panel would reflect my numbering scheme.
So, when I started experiencing corruption in a specific List Template panel, I abandoned trying to address a specific panel. An alternative would be to reset the panel you want to use before addressing it in code. But it seemed to be healthier for the List Templates panels to allow Word to use whatever panel was handy, the code worked just fine without specifying a panel, and I stopped getting reports of error messages.
I hope this extra info is helpful.
Kim
-
kdock
AskWoody PlusThanks to all of you for the input. I’ll try them all and see which works best for my situation, but I’m very grateful for the info.
K
![]() |
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 |

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
-
Can’t make Opera my default browser
by
bmeacham
1 hour, 9 minutes ago -
Do not Fall For This Purdentix Scam (Awaiting moderation)
by
elizabethkaur56
7 hours, 7 minutes ago -
*Some settings are managed by your organization
by
rlowe44
17 hours, 6 minutes ago -
Formatting of “Forward”ed e-mails
by
Scott Mills
3 minutes ago -
SmartSwitch PC Updates will only be supported through the MS Store Going Forward
by
PL1
19 hours, 45 minutes ago -
CISA warns of hackers targeting critical oil infrastructure
by
Nibbled To Death By Ducks
1 day, 4 hours ago -
AI slop
by
Susan Bradley
1 day, 3 hours ago -
Chrome : Using AI with Enhanced Protection mode
by
Alex5723
1 day, 6 hours ago -
Two blank icons
by
CR2
15 hours, 35 minutes ago -
Documents, Pictures, Desktop on OneDrive in Windows 11
by
ThePhoenix
1 day, 14 hours ago -
End of 10
by
Alex5723
1 day, 17 hours ago -
Single account cannot access printer’s automatic duplex functionality
by
Bruce
15 hours, 31 minutes ago -
test post
by
gtd12345
1 day, 23 hours ago -
Privacy and the Real ID
by
Susan Bradley
1 day, 13 hours ago -
MS-DEFCON 2: Deferring that upgrade
by
Susan Bradley
1 day, 5 hours ago -
Cant log on to oldergeeks.Com
by
WSJonharnew
2 days, 3 hours ago -
Upgrading from Win 10
by
WSjcgc50
15 hours, 40 minutes ago -
USB webcam / microphone missing after KB5050009 update
by
WSlloydkuhnle
19 hours, 14 minutes ago -
TeleMessage, a modified Signal clone used by US government has been hacked
by
Alex5723
2 days, 19 hours ago -
The story of Windows Longhorn
by
Cybertooth
2 days, 7 hours ago -
Red x next to folder on OneDrive iPadOS
by
dmt_3904
2 days, 21 hours ago -
Are manuals extinct?
by
Susan Bradley
7 hours, 12 minutes ago -
Canonical ditching Sudo for Rust Sudo -rs starting with Ubuntu
by
Alex5723
3 days, 6 hours ago -
Network Issue
by
Casey H
2 days, 17 hours ago -
Fedora Linux is now an official WSL distro
by
Alex5723
3 days, 18 hours ago -
May 2025 Office non-Security updates
by
PKCano
3 days, 19 hours ago -
Windows 10 filehistory including onedrive folder
by
Steve Bondy
3 days, 21 hours ago -
pages print on restart (Win 11 23H2)
by
cyraxote
2 days, 21 hours ago -
Windows 11 Insider Preview build 26200.5581 released to DEV
by
joep517
3 days, 23 hours ago -
Windows 11 Insider Preview build 26120.3950 (24H2) released to BETA
by
joep517
3 days, 23 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.