Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - VBA sheet export to csv and leave original file alone

Status
Not open for further replies.

remeng

Technical User
Jul 27, 2006
504
0
16
US
Hi All;

I have a small problem with exporting a specific sheet to a csv file. While the sheet exports correctly, the hosting file changes name and sets itself to a csv file which causes a lot of problems.

I recorded a macro in an effort to get some starter code, but I don't think it understands specifically what to do.

On a sheet called "Menu" the macro is pulling variables in specific text boxes. The csv file is correctly saving to that location, so there isn't an issue there. What I think is going wrong is the ActiveWorkbook.SaveAs section of code. how can I change that the the specific sheet called "data"?

Code:
file = Worksheets("Menu").file_name_txt_box
folder = Worksheets("Menu").export_location_text_box
export_data = ActiveWorkbook.Sheets("data").Select

ChDir folder
ActiveWorkbook.SaveAs file, xlCSV, CreateBackup = False

Thanks,

Mike
 
[tt]ActiveWorkbook.Sheets("data").Copy[/tt] will create a copy of the sheet in new workbook. You can process this workbook without interacting with original file. Copy method does not return a copy, you can pick it either as ActiveWorkbook, or searching in Workbooks collection.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top