Link to home
Start Free TrialLog in
Avatar of brasiman
brasiman

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of Elena Quinn
Elena Quinn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brasiman
brasiman

ASKER

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.
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?
Just to confirm, you are saving to an existing directory, correct?
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!
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!
SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Unfortunately still no luck. When in Sheet1, I run the macro, and it doesn't work.