Solved

Word 2000 VBA: Show userform from listbox selection

Posted on 2004-09-15
3
619 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 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