help

rjw29bs4

New Member
Joined
Nov 26, 2012
Messages
13
hi can someone tell me whats the error in this code please its driveing me mad

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)
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊

I also suggest that you update your forum profile (click your user name at the top right of the forum, then ‘Account details’) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
can some body help what wrong with this code
VBA Code:
 

Attachments

  • Screenshot 2023-12-09 091655.png
    Screenshot 2023-12-09 091655.png
    126.2 KB · Views: 21
Upvote 0
can some body help what wrong with this code
VBA Code:
Perhaps you need to have a practice posting code in the Test Here forum until you understand how it works.

Also, don't forget the final paragraph in my previous post.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top