I have a problem saving the XLSM workbook to the XLSX workbook in the same folder. It currently works by saving the workbook to a single folder above (parrent folder).
I want VBA to save the workbook in the same subfolder where the active workbook is located. (Note! The active workbook is not always in the same subfolder and the path is variable).
eg.
1- MyDocuments
2- SubFolder
2a- Sub-Subfolder1 -> mainWbk.xlsm
2b- Sub-Subfolder2 -> mainWbk.xlsm
2c- Sub-Subfolder3 -> mainWbk.xlsm
2d- Sub-Subfolder4 -> mainWbk.xlsm
3- SubFolder
3a- Sub-Subfolder1 -> mainWbk.xlsm
3b- Sub-Subfolder2 -> mainWbk.xlsm
3c- Sub-Subfolder3 -> mainWbk.xlsm
If I open Workbook in 'Sub-Subfolder3', I want to save (archive) active workbooks in the same folder. And so in the other "Sub-Subfolders."
This is part of the VBA code
I've tried several variants of code but it doesn't work.
Can anyone help where I'm wrong?
I want VBA to save the workbook in the same subfolder where the active workbook is located. (Note! The active workbook is not always in the same subfolder and the path is variable).
eg.
1- MyDocuments
2- SubFolder
2a- Sub-Subfolder1 -> mainWbk.xlsm
2b- Sub-Subfolder2 -> mainWbk.xlsm
2c- Sub-Subfolder3 -> mainWbk.xlsm
2d- Sub-Subfolder4 -> mainWbk.xlsm
3- SubFolder
3a- Sub-Subfolder1 -> mainWbk.xlsm
3b- Sub-Subfolder2 -> mainWbk.xlsm
3c- Sub-Subfolder3 -> mainWbk.xlsm
If I open Workbook in 'Sub-Subfolder3', I want to save (archive) active workbooks in the same folder. And so in the other "Sub-Subfolders."
This is part of the VBA code
Code:
'SaveAs xlsm to xlsx file format (as backup-archive)
Dim wsWorksheet As Worksheet
Dim path As String
Dim fname1 As String
Dim fname2 As String
For Each wsWorksheet In ActiveWorkbook.Worksheets
wsWorksheet.Unprotect Password:="123"
wsWorksheet.Range("A1:X100").Locked = True
wsWorksheet.Range("A1:X100").FormulaHidden = True
path = ActiveWorkbook.path
fname1 = Range("D1").Text 'text in Cell D1
fname2 = Range("E1").Text 'text in Cell E1
'ThisWorkbook.SaveAs "product-" & fname1 & "-" & fname2 & "_" & Format(Now, "dd-mm-yyyy_hh-mm"), 51 'optional FileFormat:=51 '????????????????
'ActiveWorkbook.SaveAs path & "product-" & fname1 & "-" & fname2 & "_" & Format(Now, "dd-mm-yyyy_hh-mm"), 51 'optional FileFormat:=51 '????????????????
ActiveWorkbook.SaveAs "product-" & fname1 & "-" & fname2 & "_" & Format(Now, "dd-mm-yyyy_hh-mm"), 51 'optional FileFormat:=51 '????????????????
Next
Can anyone help where I'm wrong?