Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default MsgBox pops up twice. Any idea why?

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default MsgBox pops up twice. Any idea why?

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





"Noah" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default MsgBox pops up twice. Any idea why?

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

"Jezebel" wrote:

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





"Noah" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default MsgBox pops up twice. Any idea why?

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy


"Noah" wrote in message
...
Thanks...that makes sense. I didn't realize that Auto_Open and

Workbook_Open
were both events.

"Jezebel" wrote:

Because you're calling it twice. Auto_Open runs automatically (call 1);

then
Workbook_Open runs automatically and calls Auto_Open (call 2).





"Noah" wrote in message
...
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







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vlookup and mutli column pops Dylan @ UAFC[_2_] Excel Worksheet Functions 9 December 18th 08 02:19 AM
Excel configuration window always pops up Lisa Setting up and Configuration of Excel 0 March 28th 07 02:42 AM
If I click a hyperlink it pops up and goes away Chris Excel Discussion (Misc queries) 1 January 12th 07 03:10 PM
Button Pops up Graph pete3589 Excel Discussion (Misc queries) 3 November 5th 05 07:03 PM
msgBox pops up twice ?? Tempy Excel Programming 4 July 29th 05 01:43 PM


All times are GMT +1. The time now is 09:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"