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(strUserForm
", 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(strUserFormNa
me & ".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: