?
Solved

Word 2000 VBA: Show userform from listbox selection

Posted on 2004-09-15
3
Medium Priority
?
631 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 1000 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

621 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