How to make user form open automatically when open a document

D

David Vo

I have a document with a user form to have several functions on the form to perform tasks
My problem is that when I open the document the user form is not open automatically
I have winxp pro with office XP
Please hel

Thanks
 
S

Sasa

Hi Dave,

Just write this code and it should work.

Sub AutoOpen

If ActiveDocument.Name = "YourDocumentName.doc" Then
UserForm1.Show
End If

End Sub

Cheers...

Sasa
 
J

Jean-Guy Marcil

Hi Sasa,

I was curious about your post...
Why
If ActiveDocument.Name = "YourDocumentName.doc" Then
UserForm1.Show
End If
?
I thought that in David's case
UserForm1.Show
would be enough, no?

Also, eventhough "Sub AutoOpen" will work, it is deprecated.
You might want to look into using the ThisDocument class module and its
Open, New and Close events. With these you often do not even need to create
a standard module.

HTH
 
S

Sasa

Might be one of possible solutions. Never thought about
using it. Nice tip. Thanks.

Cheers.

Sasa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top