Consulting

Results 1 to 3 of 3

Thread: Solved: Restrict Saving WorkBook

  1. #1

    Solved: Restrict Saving WorkBook

    Hi,

    I want to restrict people from saving a workbook using the code below. Problem is when I try to save changes after adding the code it wont let me either ...ha

    How can I add code to restrict saving?

    [VBA]
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True
    MsgBox "This work book cannot be saved"
    End Sub
    [/VBA]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True

    If Environ("username") = "MD" Then '<=== Change to suit
    Application.EnableEvents = False
    ThisWorkbook.Save
    Application.EnableEvents = True
    Else
    MsgBox "This work book cannot be saved"
    End If

    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Ahh excellent


Posting Permissions

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