I have a snippet of code in the macro, which save a macro-enabled workbook under a different name before most of the code is run:
It used to work without any issue. But recently it does not save a file under a name I chose but keeps the original name of the workbook. I do not know what happened, probably something which is run before the code or the changes in the network. Just in case, please see below the beginning of the code up to the save as part:
VBA Code:
FileSaveAs = Application.GetSaveAsFilename(FileFilter:="Exel Files (*.xlsx), *.xlsx", Title:="Select Name To Save The File")
If FileSaveAs <> False Then
ActiveWorkbook.SaveAs Filename:=FileSaveAs, _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End If
It used to work without any issue. But recently it does not save a file under a name I chose but keeps the original name of the workbook. I do not know what happened, probably something which is run before the code or the changes in the network. Just in case, please see below the beginning of the code up to the save as part:
VBA Code:
Sub UploadData()
Dim FileOpenDial As Variant
Dim FileSaveAs As Variant
Dim wb As Workbook
Dim activeWB As Workbook
Dim bFileSaveAs As Boolean
Dim finstart As Range
Dim endcell As Range, startcell As Range
Dim yearsno As Range
Dim numrowsadj As Integer
Dim cfyearsno As Range
Dim numrows As Integer
Dim numrowscf As Integer
Dim c As Range
Dim decimaltab As Range
Dim d As Range
Dim MySheets As Variant
Dim r As Range
Dim templvar As Variant
Dim cafvar As Variant
Dim tiervar As Variant
Dim wipevar As Variant
Dim SrchRng As Range, cel As Range
Dim ws As Worksheet
''Optimize Code
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
ActiveSheet.DisplayPageBreaks = False
Application.DisplayAlerts = False
UserForm1.Hide
''Import data
templvar = IIf(UserForm1.radioift, Array("Products", "Types"), Array("Products"))
Set activeWB = Application.ActiveWorkbook
FileOpenDial = Application.GetOpenFilename(FileFilter:="Excel Files (*.XML), *.XML", Title:="Select File To Be Opened")
''cancel pressed
If FileOpenDial = False Then Exit Sub
Set wb = Workbooks.Open(FileOpenDial, 0, True)
wb.Worksheets(templvar).Copy Before:=activeWB.Sheets(1)
wb.Close savechanges:=False 'or True
''Save a file
FileSaveAs = Application.GetSaveAsFilename(FileFilter:="Exel Files (*.xlsx), *.xlsx", Title:="Select Name To Save The File")
If FileSaveAs <> False Then
ActiveWorkbook.SaveAs Filename:=FileSaveAs, _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End If