OzGrid

Prevent Excel Being Saved With Another Name

< Back to Search results

 Category: [Excel]  Demo Available 

Prevent Excel Being Saved With Another Name

 

Stop Workbook Being Saved as Another Name

 

Got any Excel/VBA Questions? Free Excel Help

Preventing a Workbook From Being Saved as Another Name

The code below can be used to stop any users saving a Workbook as another name, but will allow the Workbook to be save to another location. The code must be placed in the Private Module of the Workbook Object (ThisWorkbook). The fastest way to get there is to right click on the Excel icon, top left next to File and select View Code. It is in here you should place the code below and then save the Workbook. So long as the Workbook is opened with macros enabled the code will fire anytime any user tries to use Save As.

Private Sub Workbook_BeforeSave _

              (ByVal SaveAsUI As Boolean, Cancel As Boolean)

    Dim NamePath As String

    Dim strName As String

    Dim lFind As Long



    If SaveAsUI = True Then

      Cancel = True

        With Application

                .EnableEvents = False

     NamePath = .GetSaveAsFilename

     strName = Mid(NamePath, InStrRev(NamePath, "\", -1, vbTextCompare) + 1, 256)



            If NamePath = "False" Then

                   .EnableEvents = True

                Exit Sub

            ElseIf strName <> Me.Name Then

                MsgBox "You cannot save as another name"

                    .EnableEvents = True

                Exit Sub

            Else

              Me.SaveAs NamePath

                 .EnableEvents = True

            End If

        End With

    End If



End Sub
 

See also:

Prevent Save As in Excel
Prevent Save Prompts in Excel

 

See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)