Solved

Word 2000 VBA: Show userform from listbox selection

Posted on 2004-09-15
3
615 Views
Last Modified: 2007-12-19
I'm using Word 2000 VBA and have a listbox populated by all templates loaded from the Word Startup folder. When the user selects a template, I would like VBA to show a userform from the selected template.

Here are the solutions I have tried without success:

(1) I have tried looping through all userforms in all open templates, but that only returns userform objects that are loaded. In my case, none of the userforms that could be loaded by making a selection from the listbox would be loaded already. So this method does not work.

(2) I have tried using the undocumented method "UserForms.Add(strUserFormName).Show", which doesn't add a new userform, but adds an existing userform to the collection of loaded userforms -- and then displays it. But this method simply dispays an empty existing userform with all events disabled; not very useful.

(3) I have also tried using a custom function, available for download at http://www.freevbcode.com/ShowCode.Asp?ID=1901. This mimicks the functionality of the immediate window, and in this case, would show a userform object from a string-based command line, such as "ExecuteLine(strUserFormName & ".Show")". I have not been able to make this function work, as it cannot locate the file "vba6.dll" for VBA6. I tried changing the file name to "vbe6.dll", as this seems to be the library for VBA6 (rather than VB6), but then it gave me the message: "Can't find DLL entry point EbExecuteLine in vbe6.dll". So I haven't been able to make this function work.

Essentially, the problem is trying to return an object (userform) from a string reference (listbox selection). This is proving to be a nightmare for the UserForms collection, but I can't help but think that there must be a way.

Anybody have any experience solving something like this?

See the following link for a previous discussion on this topic, which may be helpful:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21131185.html
0
Comment
Question by:PNeely
3 Comments
 
LVL 44

Assisted Solution

by:bruintje
bruintje earned 250 total points
ID: 12072737
you can try the same function from the vba332.dll

Declare Function EbExecuteLine Lib "vba332.dll"  (ByVal pStringToExec As Long, ByVal Unknownn1 As Long,  ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long

HTHAB
0
 
LVL 4

Accepted Solution

by:
Colonel32 earned 250 total points
ID: 12073290
Method 2 works fine for me, all the userform and control events work when the userform is native to the active workbook. There must be something else going on, we'd need to see more of the code, particularly the part that opens the userform from the templates.
0
 

Author Comment

by:PNeely
ID: 12256923
Thanks guys. Sorry to have taken so long to reply. I'll keep your suggestions in mind when I can get round to this project again.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now