MsgBox pops up twice. Any idea why?

G

Guest

I have a macro that runs automatically when the workbook is opened. If the
workbook is *not* opened in read-only mode, and I am the user, the macro
should unprotect the worksheet and msgbox that the worksheet has been
unprotected.

For some reason, the msgbox always appears twice when I am opening the
workbook in read/write mode. However, if I run the macro a second time when
the workbook is already open, the msgbox appears just once. Any idea why
this happens?

Thanks.

----------------------
Private Sub Workbook_Open()
Call Auto_Open
End Sub
----------------------
Sub Auto_Open()
Dim User As String
Dim R_O_Status As Boolean
R_O_Status = Workbooks("Book1").ReadOnly
User = Environ("UserName")
If R_O_Status = False Then
Select Case User
Case "Noah"
ActiveSheet.Unprotect Password:="Password"
MsgBox "Worksheet is unprotected."
Case Else
MsgBox "Worksheet remains protected."
Exit Sub
End Select
Else: MsgBox "You are in read-only mode."
End If
End Sub
 
J

Jezebel

Because you're calling it twice. Auto_Open runs automatically (call 1); then
Workbook_Open runs automatically and calls Auto_Open (call 2).
 
G

Guest

Thanks...that makes sense. I didn't realize that Auto_Open and Workbook_Open
were both events.
 

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