+ Reply to Thread
Results 1 to 4 of 4

MsgBox pops up twice. Any idea why?

  1. #1
    Noah
    Guest

    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. #2
    Jezebel
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >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. #3
    Noah
    Guest

    Re: 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" <[email protected]> wrote in message
    > news:[email protected]...
    > >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. #4
    Tom Ogilvy
    Guest

    Re: MsgBox pops up twice. Any idea why?

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

    --
    Regards,
    Tom Ogilvy


    "Noah" <[email protected]> wrote in message
    news:[email protected]...
    > 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" <[email protected]> wrote in message
    > > news:[email protected]...
    > > >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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1