Works in Excel but not Word?

W

Wayne_Perth_WA

The follwing code works in excel but not in word?
It basically checks the user name.
checks to see if user name is either "Name1" or "Name2"
If the name is either of these it lets the document be open other wise the
document closes.

Any Ideas as to why it will not work?



Private Sub Document_Open()
User = Application.UserName
Application.DisplayAlerts = False
If (User = "Name1") Or (User = "Name2") Then Beep Else Application.Quit
Application.DisplayAlerts = True
End Sub
 
J

Jonathan West

Hi Wayne,

Various things might be wrong. Since you haven't indicated whether you have
stepped through the program and seen what happens, it is hard to be sure
what the exact problem is.

The most likely problem is that you have put the code in the wrong place.
For this code to be called, it needs to be in the ThisDocument module of the
document, or of the document's attached template.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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