Macro to a specific sheet in Excel as different workbook

I have a button that runs a macro, but it isn't working. When I click the button, i am trying to save Sheet2 as filename "Import.csv" in the "C:\ToImport" folder. So the steps I manually take are:

1. Click on Sheet2
2. File>Save As>"Import.csv"

I would like to keep my original .mxlsx spreadsheet open so I can do more with it. Any help writing this macro would be appreciated! Thanks!
brasimanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Elena QuinnCommented:
Sheets("Sheet2").Select
    Sheets("Sheet2").Copy
    ActiveWorkbook.SaveAs Filename:="C:\toImport\Import.csv", _
        FileFormat:=xlCSV, CreateBackup:=False

Open in new window

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
brasimanAuthor Commented:
Thanks EQUINN. That unfortunately didn't work. Do I need Sub and End Sub at the begging and end? I tried it a few ways and it just takes me to Sheet2 but doesn't save the file.
Elena QuinnCommented:
Sorry, yes you do need a Sub and End Sub before and after.  

It works for me.  Why don't you post your code and we can have a look?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Elena QuinnCommented:
Just to confirm, you are saving to an existing directory, correct?
brasimanAuthor Commented:
Thanks EQUINN for looking at this. Here's my code:

Sub Import()
Sheets("Sheet2").Select
    Sheets("Sheet2").Copy
    ActiveWorkbook.SaveAs Filename:="C:\ToImport\Import.csv", _
        FileFormat:=xlCSV, CreateBackup:=False
End Sub

I have a button on Sheet1 that runs the macro. I don't know if that makes any difference. Correct, i am saving it to an existing directory. Thanks!
brasimanAuthor Commented:
Ok, so when I run the macro in Sheet2, it works. But when I click the button on Sheet1, it doesn't work. It just takes me to Sheet2 but doesn't do anything. How do I get this so I can click the button on Sheet1? Also, how do I get it so the new created spreadsheet doesn't open. I don't need it to open. Thanks!
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
It should work.
Try to remove Sheets("Sheet2").Select and see if that resolves the issue.
brasimanAuthor Commented:
Unfortunately still no luck. When in Sheet1, I run the macro, and it doesn't work.
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
VB Script

From novice to tech pro — start learning today.