Dear All,
The folder path will change each month, the filename changes week on week. Im trying to use the data from the cell on the Control sheet to deal with the name changes and save to a specific folder with the new file name. But alas to no avail.
Can someone please advise why it wont work?
As always, many thanks in advance.
Stuart
The folder path will change each month, the filename changes week on week. Im trying to use the data from the cell on the Control sheet to deal with the name changes and save to a specific folder with the new file name. But alas to no avail.
Can someone please advise why it wont work?
Code:
Sub Saving_Closing_File()
Dim sPath As String
'ThisWorkbook.Sheets("Control").Range("F23").Value = "File is saving...."
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.DisplayStatusBar = False
ActiveSheet.DisplayPageBreaks = False
Application.CutCopyMode = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
'ThisWorkbook.Save
Dim FPath As String
Dim FName As String
FPath = Sheets("Control").Range("C80")
FName = Sheets("Control").Range("C81").Text
If FPath = vbNullString Then Exit Sub
Filename1 = InputBox("DATE FORMAT...DD.MM.YY", "Filename")
Filename2 = "BAU Extract " & Filename1
If StrPtr(Filename1) = 0 Then
MsgBox "You pressed Cancel!"
GoTo Error
Else
If Filename1 = "" Then
End If
Sheets("Control").Range("C79") = Filename1
FP = Sheets("Control").Range("C80")
Dim Wk As Workbook
Set Wk = WorkBooks.Add
Application.DisplayAlerts = False
Dim arrSheets As Variant, sht As Variant
With Wk
ThisWorkbook.Sheets(Array("Data")).Copy Before:=Wk.Sheets(1)
End With
sarray = Array("Data")
Application.DisplayAlerts = False
For Each sht In Wk.Worksheets
If IsError(Application.Match(sht.Name, sarray, 0)) Then
sht.Delete
End If
Next sht
'*************************
'SAVE THE BAU EXTRACT FILE
'*************************
Wk.Activate
ActiveWorkbook.SaveAs FileName:=FPath & "\" & Filename2, FileFormat:=xlCSV, _
ReadOnlyRecommended:=False, _
CreateBackup:=False
ThisWorkbook.Activate
ThisWorkbook.Sheets("Control").Range("J11") = "Extract Saved"
ThisWorkbook.Sheets("Control").Range("J6").ClearContents
ThisWorkbook.Sheets("Control").Range("J9").ClearContents
ThisWorkbook.Sheets("Control").Range("F23").ClearContents
Wk.Close
Application.ScreenUpdating = False
Error:
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.DisplayStatusBar = True
ActiveSheet.DisplayPageBreaks = False
Application.CutCopyMode = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End If
End Sub
As always, many thanks in advance.
Stuart