Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading and showing a userfrom in MSWord

Status
Not open for further replies.

ApK

Technical User
Apr 14, 2004
3
NL
I have created two identical userforms in MSExcel and MSWord (97). The initialization of the form takes several seconds,so I want to load it at startup of the application, and show it when requested by the user. The userform_initialize routine is called when the form is loaded. In Excel this works fine, in Word it doesn't. When the .show function is called in Word, the initialize routine is called again. userforms.count gives a count of 0.
Can someone tell me if (what) i'm doing (something) wrong?
This is the Word code:
Code:
[COLOR=blue]Sub[/color blue] AutoExec()
    Load ufmWVGadressen
[COLOR=blue]End Sub[/color blue]

[COLOR=blue]Sub[/color blue] AdresInvoegen()
    ufmWVGadressen.Show
[COLOR=blue]End Sub[/color blue]
Thank you![/color navy]

 
Hi ApK,

I think the AutoExec runs BEFORE any documents are loaded which would mean that your Userform cannot be loaded from it. I would, however, expect you to get an error message. Can you post a bit more detail or, at least, confirm that the initialise code really does run twice, and not just once when you Show the Form.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Yes, more detail is needed. It seems to be that you want a Word form to load, but not be visible to the user? It only becomes visible when "requested by the user"?

How are you processing that request?

If this is the case, load (show) the form (which fires the initialization), but immediately hide it. It is now loaded but not visible. Use whatever code you are using for the user to request the form simply make it visible. If there could be multiple uses of the form (i.e. it becomes visible/not visible a number of times) remember to do a final unload of the form!

This is in This Document. It loads the form, firing userform_initialize.

Code:
Private Sub Document_Open()
    Application.ScreenUpdating = False
    Load UserForm1
End Sub

This is in the Userform - immediately hiding it.

Code:
Private Sub UserForm_Initialize()
    Me.Hide
End Sub

Private Sub CommandButton1_Click()
    Unload Me
End Sub

This is in a code module. I put it as a hot key, but use whatever method you have for the user to request the form.

Code:
Sub ShowTheForm()
'hotkey = Alt-S
    UserForm1.Show
End Sub

Hope this helps.


Gerry
 
Tony and Gerri,
Thanks for your advice.
Tony, jou got me in the right direction. It IS possible to load a userform without having a document open. In my case the userform was opened from a global template. I had started Word with the global template AND had opened a seperate copy of this document. I was modifing things in 2 documents and that caused unpredictable results. Getting things straight in one document solved the problem.
Gerri, when you load a document it is not visible. You have to perform a show instruction to make it visible. I use a self-defined button. The way you address forms is nice. I'm going to do that to!
Anyway thank al lot for your fast response.
Ap[/color navy]
 
Hi ApK,

Glad you're sorted. I hadn't thought about having a Userform in a Template [smile]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top