I have a template that I do a fast paste from the main workbook. Then I want to save the template with a unique name. But, it tosses up an error.
I thought it was fairly straightforward but I get this error and am not certain what I did wrong. I got the code from various google searches and put it together.
Code:
Sub Export()
Workbooks.Open FileName:=ThisWorkbook.Path & "\RSP PO Form Template New.xlsx"
Workbooks("DISH ORDER WORKSHEET.xlsB").Worksheets("Subcontractor PO Form").Range("H17:H500").Copy
Workbooks("RSP PO Form Template New.xlsx").Worksheets("RSP PO Form").Range("H17").PasteSpecial Paste:=xlPasteValues
'Saves copy of workbook to filename as value of Q1
Windows("RSP PO Form Template New.xlsx").Activate
Dim PathName, FileName As String
FileName = Range("Q1").Value & ".xlsx"
If Len(FileName) > 0 Then
PathName = ThisWorkbook.Path
If Dir(PathName, vbDirectory) = "" Then MkDir PathName
ThisWorkbook.SaveAs PathName & "\" & FileName
Else
Range("q1").Select
MsgBox "File name in P1 is not found", vbExclamation, "Not saved": Exit Sub
End If
Range("F10").Select
End Sub
I thought it was fairly straightforward but I get this error and am not certain what I did wrong. I got the code from various google searches and put it together.