Solved

Word 2000 VBA: Show userform from listbox selection

Posted on 2004-09-15
3
622 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

739 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