Announcement

Collapse
No announcement yet.

Temporarily stopping an inputbox in a sub

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Temporarily stopping an inputbox in a sub

    Hello,

    I have the following sub in a Workbook to prevent users of a spreadsheet from saving it:

    Code:
    Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim Password As String
    Dim EnteredPassword As String
    
    
    Password = "1234"
    EnteredPassword = InputBox("Enter password to save changes")
    If EnteredPassword <> Password Then
    Cancel = True
    MsgBox ("Password incorrect, file not saved")
    End If
    
    
    End Sub
    There is another sub that runs after the user clicks a button on a worksheet. During this script the worksheets are saved as different .csv files to be used by another program.

    How can I avoid the pop up asking for a password to save during that part of the code?

    Thanks,
    Ross

  • #2
    Re: Temporarily stopping an inputbox in a sub

    With the other subroutine put this at the start of the code
    Code:
    Application.EnableEvents = False
    and this at the end
    Code:
    Application.EnableEvents = True
    We now have a reputation system in place. It can be found on the 'Star' icon on the bottom left hand side of the post

    Comment


    • #3
      Re: Temporarily stopping an inputbox in a sub

      That works! Thanks

      Comment


      • #4
        Re: Temporarily stopping an inputbox in a sub

        You're welcome.
        We now have a reputation system in place. It can be found on the 'Star' icon on the bottom left hand side of the post

        Comment

        Working...
        X