Elena Margulis
New Member
- Joined
- Aug 21, 2020
- Messages
- 25
- Office Version
- 365
- Platform
- Windows
Hello,
I have macro enabled Ms Excel Worksheet (data entry Form) with various procedures and data in it.
I have one part of the vba code in it, where it should create a backup copy of the sheet - right after opening it:
This code should create a Worksheet copy inside of created [Backup Data] folder.
The folder path is stored in a [Config] Sheet, in front of a [FolderPathBackup] cell: (I highlighted in blue)
The problem - for some reason, it only works (creates a backup copy of the Worksheet) if I'd created this folder on E:\Projects\Client Satisfaction Survey
But , if I want to move my backup file to E:\BackupData - no copy is created (empty folder as a result).
I am not proficient in vba - and don't understand - where else is this path (E:\Projects\Client Satisfaction Survey) still exists in this vba code?
Or - what should I update in the code, in order to be able to just modify A4 cell (FolderPathBackup reference) so that the copy would be saved on E:\BackupData (or anywhere I write in front of FolderPathBackup)
Thank you for any help, suggestions!
I have macro enabled Ms Excel Worksheet (data entry Form) with various procedures and data in it.
I have one part of the vba code in it, where it should create a backup copy of the sheet - right after opening it:
VBA Code:
Private Sub Workbook_Open()
Dim wb As Workbook, shA As Worksheet, shC As Worksheet
Dim sh As Worksheet, i As Long, strBackup As String, arr As Variant
Set shC = ThisWorkbook.ActiveSheet
strBackup = Range(ThisWorkbook.Names("FolderPathBackup")).Value
Set wb = Workbooks.Add
shC.Copy before:=wb.Worksheets(1)
Set shA = wb.Worksheets(1)
If wb.Worksheets.Count > 1 Then
'delete all sheets, except the first
For i = wb.Worksheets.Count To 2 Step -1
Application.DisplayAlerts = False
wb.Worksheets(i).Delete
Application.DisplayAlerts = False
Next i
End If
arr = Split(strBackup, ".")
arr(UBound(arr)) = "xlsx"
strBackup = Join(arr, ".")
wb.SaveAs strBackup, xlWorkbookDefault
wb.Close False
This code should create a Worksheet copy inside of created [Backup Data] folder.
The folder path is stored in a [Config] Sheet, in front of a [FolderPathBackup] cell: (I highlighted in blue)
The problem - for some reason, it only works (creates a backup copy of the Worksheet) if I'd created this folder on E:\Projects\Client Satisfaction Survey
But , if I want to move my backup file to E:\BackupData - no copy is created (empty folder as a result).
I am not proficient in vba - and don't understand - where else is this path (E:\Projects\Client Satisfaction Survey) still exists in this vba code?
Or - what should I update in the code, in order to be able to just modify A4 cell (FolderPathBackup reference) so that the copy would be saved on E:\BackupData (or anywhere I write in front of FolderPathBackup)
Thank you for any help, suggestions!