copy and paste the data from one file to another file

my 1st file name is OneClick.xlsb  located in C:\Users\user\Desktop
my 2nd file name is BasketOrder.csv located in C:\Users\user\Desktop
my code will be placed in OneClick.xlsb
now what i want copy sheet5 from OneClick.xlsb and paste to BasketOrder.(this is a sheet name in BasketOrder.csv ) of  BasketOrder.csv
(If there is a data in  BasketOrder.csv file then first delete the data then paste the data)
plz see the attached  file
Sachin SinghAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
Why not just save the sheet to csv?
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Please give this a try...
Following code assumes that both the .xlsb and .csv files are saved in the same folder.

Sub SaveSheet5AsCSV()
Dim ws As Worksheet
Dim strFilePath As String, strFileName As String

Application.ScreenUpdating = False
Application.DisplayAlerts = False

strFilePath = ThisWorkbook.Path & "\"
strFileName = "BasketOrder.csv"
Set ws = Sheets("Sheet5")
ActiveWorkbook.SaveAs strFilePath & strFileName, xlCSV, , , , False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Sheet5 has been saved as csv file successfully.", vbInformation
End Sub

Open in new window

In the attached, click the button called "SaveAs CSV" to run the code.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sachin SinghAuthor Commented:
Thnx Neeraj Sir & Roy Cox Sir for ur great Support
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Roy CoxGroup Finance ManagerCommented:

Had to nip out. Here's my suggestion

Option Explicit

Sub SaveSheetToCSV()

    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False

        ''/// sheet to copy to csv. Copy will copy the sheet to a new workbook automatically because no workbook is specified
        ''// save as csv file, use NOW to add unique identifier
        ActiveWorkbook.SaveAs ThisWorkbook.Path & .PathSeparator & "BasketOrder_" _
                            & Format(Now, "ddmmyyyy hhmm"), xlCSV, False
        ''/// close csv

        .DisplayAlerts = True
        .ScreenUpdating = True
    End With
    MsgBox "Done", vbInformation
End Sub

Open in new window

Roy CoxGroup Finance ManagerCommented:
Bit of a rush!!
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Sachin!
Sachin SinghAuthor Commented:
Thnx Roy Cox Sir for ur great support
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.