hi can someone tell me whats the error in this code please its driveing me mad
it goes wrong at (ActiveWorkbook.SaveAs newfn, FileFormat:=xlOpenXMLWorkbook)
VBA Code:
Sub copysave()
'copy invoice to a new workbook
ActiveSheet.Copy
newfn = "g:\INVOICES BACKUP\ALL\" & Range("e4").Value & "." & Range("a10") & ".xlsx"
ActiveWorkbook.SaveAs newfn, FileFormat:=xlOpenXMLWorkbook
ActiveSheet.PrintOut
ActiveWorkbook.Close
'Set Destn = Worksheets("INPUT")
NextRow = Worksheets("INPUT").Range("A" & Rows.Count).End(xlUp).Row + 1 'uses column A to identify the next empty row; adjust yourself if column A is not suitable
Set Destn = Worksheets("INPUT").Cells(NextRow, "A")
With Worksheets("copy and close")
.Range("e4").Copy Destn
.Range("a10").Copy Destn.Offset(, 1)
.Range("e3").Copy Destn.Offset(, 2)
Destn.Offset(, 3).Value = .Range("E31").Value
Destn.Offset(, 4).Value = .Range("e33").Value
Destn.Offset(, 5).Value = .Range("e32").Value
End With
'Set Destn = Worksheets("YE_23_24")
NextRow = Worksheets("YE_23_24").Range("A" & Rows.Count).End(xlUp).Row + 1 'uses column A to identify the next empty row; adjust yourself if column A is not suitable
Set Destn = Worksheets("YE_23_24").Cells(NextRow, "A")
With Worksheets("copy and close")
.Range("e4").Copy Destn
.Range("a10").Copy Destn.Offset(, 1)
.Range("e3").Copy Destn.Offset(, 2)
Destn.Offset(, 3).Value = .Range("E31").Value
Destn.Offset(, 4).Value = .Range("e33").Value
Destn.Offset(, 5).Value = .Range("e32").Value
End With
'copy invoice to a new onedrive
ActiveSheet.Copy
newfn = "C:\Users\rwbr2\OneDrive\Documents\aaa\" & Range("e4").Value & "." & Range("a10") & ".xlsx"
ActiveWorkbook.SaveAs newfn, FileFormat:=xlOpenXMLWorkbook
'copy invoice to a new workbook
ActiveSheet.Copy
newfn = "C:\Users\rwbr2\Documents\aaa\" & Range("e4").Value & "." & Range("a10") & ".xlsx"
ActiveWorkbook.SaveAs newfn, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
Range("e4").Value = Range("e4").Value + 1
Range("a18:d30").ClearContents
Range("E3").ClearContents
Range("a10").ClearContents
ActiveWorkbook.Close
End Sub
it goes wrong at (ActiveWorkbook.SaveAs newfn, FileFormat:=xlOpenXMLWorkbook)