Realtreegirl75
New Member
- Joined
- Aug 28, 2022
- Messages
- 40
- Office Version
- 365
- Platform
- Windows
I have a report that I have created that does a lot of things in the back end that I need people to stop using the "Save" or "Save As" Buttons in the ribbon to bypass. I just found this and it disables Save and Save As (but adds the ability to use a password to bypass the disabled functions) so that the user has to use the macro button that does all the back-end stuff that needs to be done:
This is the code I have tied to my macro-save button. It pulls information from the report to save the file but lets the user save the file in whatever location they want. It also ends the sub if the user clicks "Cancel" instead of saving the report:
So now I'm left with the question of how to get my button to run. Anyone have any ideas? Or suggestions about how I'm going about this in an entirely useless and round-about way?
VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = True Then
Cancel = True
MsgBox ("Save as function is disabled.")
ElseIf ThisWorkbook.Saved = True Then
a = InputBox("password:", "you need a password to save this workbook")
If a = "123" Then
MsgBox ("workbook is saved.")
Else
Cancel = True
MsgBox ("Workbook isn't saved.")
End If
End If
End Sub
This is the code I have tied to my macro-save button. It pulls information from the report to save the file but lets the user save the file in whatever location they want. It also ends the sub if the user clicks "Cancel" instead of saving the report:
VBA Code:
Sub Test_Save()
Dim tdayName As String
Dim no1 As String
Dim tday As String
Dim no2 As String
Dim tmrName As String
Dim tmr As String
Dim FolderPath1 As String
If Val(Application.Version) > 15 Then
If ActiveWorkbook.AutoSaveOn Then ActiveWorkbook.AutoSaveOn = False
End If
no1 = Range("r3").Text
tday = Range("ac4").Text
no2 = Range("E6").Text
tmr = Range("T237").Text
FolderPath1 = Application.ThisWorkbook.Path & "/"
tdayName = "DIR - " & no1 & " - " & tday & " - " & no2
tmrName = "DIR - " & no1 & " - " & tmr & " - " & no2
Application.DisplayAlerts = False
FileSaveName = Application.GetSaveAsFilename(InitialFileName:=tdayName, filefilter:="Excel Files(*.xlsm),*.xlsm", Title:="Please save the file")
If FileSaveName = False Then Exit Sub
ThisWorkbook.SaveAs Filename:=FileSaveName, FileFormat:=52
If Val(Application.Version) > 15 Then
If ActiveWorkbook.AutoSaveOn Then ActiveWorkbook.AutoSaveOn = False
End If
End Sub
So now I'm left with the question of how to get my button to run. Anyone have any ideas? Or suggestions about how I'm going about this in an entirely useless and round-about way?