I am working on a timesheet that, when submitted, will send an email telling payroll it's been submitted and will include notes from the workbook as well as save a csv copy of a part of the timesheet and put it on a network drive for auto-import. The first part is working fine, this part is driving me nuts. I have another file written THE SAME WAY that works without issue. I've read easily 50 threads and nothing has worked. Please help. Bolded section is where it continually fails. BTW - I have recorded a Macro, used that code, and still it fails. I'm assuming there is something with, when it's trying to auto save, maybe the right workbook isn't active vs. when I manually save, excel knows what workbook I'm on.
Sub CreateFile()
Dim sRange1 As String
Sheets("Timesheet").Unprotect Password:="sas"
sRange1 = Sheets("Timesheet").Range("L1")
Sheets("Timesheet").Select
Sheets("Timesheet").Range("A1:K500").Select
Selection.Copy
Dim xWs As Worksheet
Dim Rng As Range
Set Rng = Application.Selection
Application.Workbooks.Add
Set xWs = Application.ActiveSheet
Rng.Copy Destination:=xWs.Range("A1")
ActiveWorkbook.SaveAs Filename:= _
"\\Steg\AutoImports\Timesheets\Pickup" & "testSAS", FileFormat:=xlCSV, CreateBackup:=False
ActiveWindow.Close
ActiveWorkbook.Close savechanges:=False
End Sub
Sub CreateFile()
Dim sRange1 As String
Sheets("Timesheet").Unprotect Password:="sas"
sRange1 = Sheets("Timesheet").Range("L1")
Sheets("Timesheet").Select
Sheets("Timesheet").Range("A1:K500").Select
Selection.Copy
Dim xWs As Worksheet
Dim Rng As Range
Set Rng = Application.Selection
Application.Workbooks.Add
Set xWs = Application.ActiveSheet
Rng.Copy Destination:=xWs.Range("A1")
ActiveWorkbook.SaveAs Filename:= _
"\\Steg\AutoImports\Timesheets\Pickup" & "testSAS", FileFormat:=xlCSV, CreateBackup:=False
ActiveWindow.Close
ActiveWorkbook.Close savechanges:=False
End Sub