-
WSTroyWells
AskWoody LoungerSeptember 3, 2001 at 9:42 pm in reply to: Form Hides and doesn’t save variable values (Word 2000 VBA) #540428Regarding the “Weird” comment, I must have created this and moved it somewhere else and forgot to remove it here. You are right to say that is unnecessary. Good catch!!
Regarding the Cancel and Terminate issue: You were right!! I had a lot of code in there I didn’t need. Once I removed this code the problem went away. I still don’t know which part of the code that I deleted caused the problem I was experiencing, but I think it would be best to not worry about that until it happens again.
Thanks again for all your help!!
Troy -
WSTroyWells
AskWoody LoungerSeptember 3, 2001 at 5:53 pm in reply to: Form Hides and doesn’t save variable values (Word 2000 VBA) #540354Edited by TroyWells on 03-Sep-01 18:53.
UPDATE: I had the wrong attachment attached. Sorry for any confusion.
TroyI agree that my problems where caused by my use of the “Exit” event. So I changed the “Exit Event code to the “Terminate” event.
KEY: What I was trying to accomplish with this code is to make the control menus (right-click on the title bar and click “Close”, ALT+F4, and the little “X” in the upper right corner do the same thing as the “Cancel” button. (Sorry, I probably should have mentioned this in my first post.)
PROBLEM: When I put the same code in the “Terminate” event, as soon as I show the main form, it resets all the properties to whatever they were when the form was activated.
For example:
1. Run the form.
2. Click on the Options button or the check box.
3. Click a check box, and click OK.
4. Click the Options button.
5. Right-click on the title bar and click “Close”, or press ALT+F4, or click the little “X” in the upper right corner.
The main form reappears but the options on the other form are reset to their default (i.e. it doesn’t retain the check mark you applied in step 3.I tried commenting out “frmFormatDocumentMain.Show”, but all that does is return the focus to the document with the form still visible. Once I click the form again (i.e. the form gets the focus) it resets everything.
I have attached the document including changes I made in response to your first reply.
Thanks again for your help!!
Troy -
WSTroyWells
AskWoody LoungerThanks to all who gave such wonderful and teaching advice. I learned a lot from all of you. Feel free to continue if you have something to add, but at this point, I think I am going to go with Geoff’s solution.
HOWEVER, I found that I need to add a couple of lines or I ended up with an endless loop if I moved one item to a list that was already empty:
‘Added this first “If line and the corresponding “End If” below
If lbIncludeTextIn.ListCount > 1 Then
Dim blnSorted As Boolean
Dim strTemp As String
blnSorted = False
Do Until blnSorted
For i = 0 To lbIncludeTextIn.ListCount – 2
If LCase$(lbIncludeTextIn.List(i)) > LCase$(lbIncludeTextIn.List(i + 1)) Then
strTemp = lbIncludeTextIn.List(i)
lbIncludeTextIn.List(i) = lbIncludeTextIn.List(i + 1)
lbIncludeTextIn.List(i + 1) = strTemp
Exit For
End IfIf i = lbIncludeTextIn.ListCount – 2 Then
blnSorted = True
End If
Next
Loop
End IfThanks BigKev for the QuickSort demo. It was quite honestly over my head
. I couldn’t quite figure out how it worked or where to put the list name.
Thanks Gary for the referral to MS OfficePro. My trial period just expired, but I think I’m going to buy a subscription. Seems like there is a lot of good stuff there.
Thanks also to jscher2000 for your posts. You started me off simple, which helped me understand the more complex posts of yourself and others.
I look forward to seeing what you have Chris. Let us know when your site is back in working order!! Thanks also to Kevin for your initial post.
You guys are the best!!
Troy -
WSTroyWells
AskWoody LoungerI think we may be halfway there. I can get to your home page and look around (impressive!)
, but when I try to download anything, I get a page that says “Page not found”.
Thanks again for your help!!
Troy -
WSTroyWells
AskWoody LoungerEdited by TroyWells on 23-Aug-01 11:37.
Geoff,
Please see problem in 3.b below
In the interest of learning, I had a few questions about the code below:
1. Could you give a breif explanation of what a “Bubble Sort” is? I have heard this term before, but did not understand it.
2. What is the advantages/disadvantages of this code over what “jscher2000” posted below yours? Or is it just a different approach?
3. I don’t quite get what is happening in your first “If” statement. Obviously, this is the guts of the Bubble Sort, but I’m not sure I get what is happening. As I look at it, it seems you are looking at the first item in the list and comparing it to the second item. If the first item is greater (further down the alphabet or has a higher character code), you are switching the places of the first and second item in the list and so on to the end of the list.
a. What is the purpose of the “strTemp = lbIncludeTextIn.List(i)” statement. It doesn’t appear that you use “strTemp” later anywhere, so why do you define it here?
b. In the statement “lbIncludeTextIn.List(i) = lbIncludeTextIn.List(i + 1)”, what keeps “List(i)” from overwriting “List(i+1)”,
and visa-versa in “lbIncludeTextIn.List(i + 1) = lbIncludeTextIn.List(i)”? In fact, in my testing that seems to be exactly what happens!! Every item in “lbIncludeTextIn” is now named the same as what was previously the first item in the list.Thanks for your help!!
Troy -
WSTroyWells
AskWoody LoungerChris,
Thanks for your reply. Unfortunately, I cannot access the link you included. If I put the full link it says “Page not found”. If I put in part of the link, it says I am not authorized to open the page.I’d love to see these utilities.
Thanks!!
Troy -
WSTroyWells
AskWoody LoungerYou know what? This actually works, MOSTLY.
How do I get it not to consider the case? For instance, I want “Test1” to come before “test2”. Right now “test2” comes first because it has a lowercase “t”.
One other question, just for my learnin’: What does the “Me.” do when you add it before the list box name as you did 4 times below?
Thanks!!
Troy -
WSTroyWells
AskWoody LoungerThanks for your response. I tried to follow what you gave me but I am getting a run time error.
Let me give you what I have:
ListElements is my array.
lbIncludeTextIn is my list box.This is my code:
Dim ListElements() As Variant ‘Dimming my array.
ListElements() = lbIncludeTextIn.List ‘Adding list items to my array.
WordBasic.SortArray (ListElements()) ‘Sorting the array.
lbIncludeTextIn.Clear ‘Emptying the current contents of the list box.
lbIncludeTextIn.List = ListElements() ‘Filling list box with sorted contents of array.
End SubThanks for your help!!
Troy -
WSTroyWells
AskWoody LoungerThanks for the demo!! I couldn’t tell for sure how you made them sort properly.
Getting them to go back and forth is no problem now. I actually have 3 lists and I have two buttons between each list to go in either direction. Appropriate buttons are displayed and enabled, displayed and disabled from the click event of each list box.
Now, I have searched around the vba lounge for a way to have these sort alphabetically. This is an issue because I will be adding random names to these lists and would like them to automatically be sorted. I figure the code could be put in the Change event for the list box. But what I need is the how to sort in a list box (one column, could include letters or digits). I have seen some of your responses in other posts, but they seem far more complex than I need.
Thanks again for all your help!!
Troy -
WSTroyWells
AskWoody LoungerI though that worked great!! However, one problem, when I selected the last item in the list and clicked the command button to move them, it moved that item and the item above it, which was NOT selected.
I thought that may have had something to do with the MultiSelect property (set at the time to “fmMultiSelectSingle”) on my ListBox. So I changed it to “fmMultiSelectExtented” which is what I wanted anyway. Then I found that selecting an item did not activate the command buttons as it had previously. It also did not deselect when I clicked on an item in another list. This was working when I used “fmMultiSelectSingle”. I know this is a different issue than I asked before, but would appreciate any help you could give.
Also, I want to learn a little more about the code you sent. I may not use the right terminology, so please correct me when I’m wrong.
intcounter is what, a function, a method? I couldn’t find any info about it on msdn or in the online help for vba. Or is it an ingenious combination of “int” and “counter”?
It appears to count as you say from the last item in the list (which is the total of the items in the list minus 1 because the ListCount starts at 0. Right?
Is this the only way to refer to items in a list box? It appears the ListEntry object only applies to drop-down lists. This was probably my biggest hangup. I was trying to use a For Each statement and Dimmed “li” as a ListEntry.
I think I get the rest. Thanks for taking the time to help and educate a newbie!!
Troy
-
WSTroyWells
AskWoody LoungerAugust 17, 2001 at 1:28 pm in reply to: How to end a repetitive search/replace routine? (Word2000) #537911I wanted to reply to give the full path to each of these documents, at least as of today, in case someone else goes and looks for them. Gary, you gave me enough to get me there, but it still wasn’t easy (no fault of yours), so I wanted to put it all down here for the sake of others. The paths are really not even close after the first level of the TOC.
For Office 97 Visual Basic Programmer’s Guide:
http://www.msdn.microsoft.com/library/
Then in the Table of Contents in the left pane:
Office Solutions Development
Microsoft Office
Microsoft Office 97
Product Documentation
Office
Microsoft Office 97/Visual Basic Programmer’s GuideFor Office 2000 Visual Basic Programmer’s Guide
http://www.msdn.microsoft.com/library/
Then in the Table of Contents in the left pane:
Office Solutions Development
Microsoft Office Developer
Microsoft Office 2000 Developer
Microsoft Office 2000/Visual Basic Programmer’s GuideEnjoy!!
Troy -
WSTroyWells
AskWoody LoungerAugust 16, 2001 at 1:19 pm in reply to: How to end a repetitive search/replace routine? (Word2000) #537702Gary,
You mentioned the “Office 97 and Office 2000 VB Programmers Guides”.I tried searching MSDN for these but am having a hard time finding them. You don’t happen to have them bookmarked do you? Or have some other clues to help find them.
Thanks!!
Troy -
WSTroyWells
AskWoody LoungerThis works beautifully. Thanks for your help!!
Troy -
WSTroyWells
AskWoody LoungerNo problem about being crabby. I get that way to sometimes.
As far as the changes, let me tell you the affect:
1. The macro now looks through a list of all built in styles in Word, not just the list of built in styles stored in the document. So the of built-in styles included in the output list is much longer now than the number of built-in styles actually stored in the document.
For example, when I look at the styles stored in my document in Organizer (Format>Styles>Organizer command button), among others I see the following styles that start with “L”
Labels
Letter
List
List 10+
List sub
List+RTab
List Button
List Number(Some of this are built-in and some are not.)
The styles found included:
Labels
Letter
Line Number
List 10+
List 2
List 3
List 4
List 5
List Bullet
List Bullet 2
List Bullet 3
List Bullet 4
List Bullet 5
List Continue
List Continue 2
List Continue 3
List Continue 4
List Continue 5
List Number
List Number 2
List Number 3
List Number 4
List Number 5
List sub
List+RTab
ListButton
ListNumber2. One other side affect (which I have also seen after trying to use the Find function (CTRL+F) to find a built-in style that actually was not stored in my document) is that now all the built-in styles contained in Word appear in the Organizer as styles stored in this document. That gives me more styles I will have to delete and more work later.
Hey, here is an interesting thought. After solving the problem mentioned above (and I would like the ability to list the unused styles despite what I am about to ask), could we add a line of code to this macro that would delete these unused styles from the document?
Thanks again for all your help!!
Troy -
WSTroyWells
AskWoody LoungerThanks for the response. Sorry you got shafted by WordTips. I was kind of surprised because I have gotten a lot of good information from them. Oh well, I guess noone’s perfect.
Speaking of which, this macro ran great, EXCEPT:
It only showed unused user defined styles. I want to also see unused built in styles. Any suggestions/additions to the original macro that could accomplish this?
Thanks again for your help!!
Troy
![]() |
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
-
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
2 minutes ago -
Creating an Index in Word 365
by
CWBillow
8 minutes ago -
Coming at Word 365 and Table of Contents
by
CWBillow
13 minutes ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
5 hours, 9 minutes ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
8 hours, 35 minutes ago -
W11 24H2 – Susan Bradley
by
G Pickerell
10 hours, 30 minutes ago -
7 tips to get the most out of Windows 11
by
Alex5723
8 hours, 31 minutes ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
1 hour, 53 minutes ago -
I installed Windows 11 24H2
by
Will Fastie
12 minutes ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
13 hours, 57 minutes ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
53 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
22 hours, 12 minutes ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
6 hours, 24 minutes ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
6 hours, 39 minutes ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
1 day, 15 hours ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
1 day, 23 hours ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
1 day, 2 hours ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
1 day, 8 hours ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
1 day, 18 hours ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
3 days, 10 hours ago -
50 years and counting
by
Susan Bradley
8 hours, 49 minutes ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
11 hours, 38 minutes ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
3 days, 21 hours ago -
Edge : Deprecating window.external.getHostEnvironmentValue()
by
Alex5723
3 days, 21 hours ago -
Rethinking Extension Data Consent: Clarity, Consistency, and Control
by
Alex5723
3 days, 21 hours ago -
OneNote and MS Word 365
by
CWBillow
3 days, 23 hours ago -
Ultimate Mac Buyers Guide 2025: Which Mac is Right For You?
by
Alex5723
3 days, 23 hours ago -
Intel Unison support ends on Windows 11 in June
by
Alex5723
3 days, 23 hours ago -
April 2025 — still issues with AMD + 24H2
by
Kevin Jones
1 day, 15 hours ago -
Windows 11 Insider Preview build 26200.5518 released to DEV
by
joep517
4 days, 11 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.