Ambiguous name detected

Vtookup

Board Regular
Joined
May 30, 2017
Messages
137
Office Version
  1. 2016
  2. 2013
Hi.
Please help me with these codes. Don't know how to rename or merge these as single code.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim backupfolder As String
backupfolder = "C:\Backup\"
ThisWorkbook.SaveCopyAs Filename:=backupfolder & ThisWorkbook.Name
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = SaveAsUI
End Sub

Thanks in advance for the help.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Can you explain exactly what you are trying to accomplish with both of these codes?
Just want to make sure I fully understand your intentions, especially as it relates to "Save" vs. "SaveAs".
 
Upvote 0
Hi Joe4.
Thanks for the reply.
I'm using a compiler to turn excel into exe file. by "Save" function, the file remain an exe file even backup.
by "SaveAs", it save into an xlsm. That's why I need to disable "SaveAs".
I hope that make sense. Thanks again.
 
Upvote 0
How about something like this?
VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Cancel = SaveAsUI

Dim backupfolder As String
backupfolder = "C:\Backup\"
ThisWorkbook.SaveCopyAs Filename:=backupfolder & ThisWorkbook.Name

End Sub
 
Upvote 0
Solution
Thank you for the code. It works.
One more question, After
ThisWorkbook.SaveCopyAs Filename:=backupfolder & ThisWorkbook.Name
I Add MsgBox "Backup File Saved". I tried to "SaveAs" Although it does not execute, Msgbox "Backup File Saved" continue to show up.
Joe, can I have another request, to have another msgbox if SaveAs is pressed... like "SaveAs Disabled"?
Thank You.
 
Upvote 0
Maybe something like:
VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim backupfolder As String

Cancel = SaveAsUI

If Cancel = False  Then
    MsgBox "SaveAs Disabled"
Else
    backupfolder = "C:\Backup\"
    ThisWorkbook.SaveCopyAs Filename:=backupfolder & ThisWorkbook.Name
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top