Another try: I tested for the sheets of interest and the paths needed, but failed to test to see if the files have been previously created...
Option Explicit
Sub example()
' |
Const PATH As String = "\\test\test1\Review 2017\"
Dim WB As Workbook
Dim WKS As Worksheet
Dim shtAccountInput As Worksheet
Dim shtPR2017 As Worksheet
Dim strAccountName As String
Dim strAccountNumber As String
Dim strDateNow As String
'Assumes we are saving thisworkbook and a sheet from it...
'Attempt to set a reference to the sheets needed
On Error Resume Next
Set shtAccountInput = ThisWorkbook.Worksheets("Account Input")
Set shtPR2017 = ThisWorkbook.Worksheets("PR2017")
On Error GoTo 0
'If both sheets exist
If (Not shtAccountInput Is Nothing) And (Not shtPR2017 Is Nothing) Then
'If both paths exist
If CBool(Len(Dir(PATH & "Full Model\", vbDirectory))) And CBool(Len(Dir(PATH & "For Matlab\", vbDirectory))) Then
'If B45 is a valid date and we're a .xls format
If IsDate(shtAccountInput.Cells(45, "B").Value) And ThisWorkbook.FileFormat = xlExcel8 Then
strAccountName = shtAccountInput.Cells(3, "B").Value
strAccountNumber = shtAccountInput.Cells(4, "B").Value
strDateNow = Format(shtAccountInput.Cells(45, "B").Value, "yyyy-mm-dd")
'create a new one-sheet book
Set WB = Workbooks.Add(xlWBATWorksheet)
'Copy each sheet to the new workbook while leaving any standard module code behind
For Each WKS In ThisWorkbook.Worksheets
WKS.Copy After:=WB.Worksheets(WB.Worksheets.Count)
Next
'Kill the initial sheet
Application.DisplayAlerts = False
WB.Worksheets(1).Delete
Application.DisplayAlerts = True
WB.SaveAs PATH & "Full Model\" & strAccountName & Chr$(32) & strAccountNumber & Chr$(32) & strDateNow & ".xls", xlExcel8
WB.Close False
'SAA
Set WB = Workbooks.Add(xlWBATWorksheet)
shtPR2017.Copy After:=WB.Worksheets(1)
Application.DisplayAlerts = False
WB.Worksheets(1).Delete
Application.DisplayAlerts = True
WB.SaveAs PATH & "For Matlab\" & strAccountName & Chr$(32) & strAccountNumber & Chr$(32) & strDateNow & ".xls", xlExcel8
WB.Close False
End If
End If
End If
End Sub
Hope that helps,
Mark