Home > other >  How to use VBA to specify EXCEL Sheet to generate a CSV file
How to use VBA to specify EXCEL Sheet to generate a CSV file

Time:12-04

Good the great god,

I, just a little accounting, should have a good account to every day but now bosses asked us to automation , I was afraid of computer programming I also helpless to join the program apologise, there is now a very simple requirements, see what a great god can show just a little, little women in this thank you very much  !

1. A control is added in the sheet 1 "generated CSV";



2. Click "generate CSV" control can make the data in the sheet A and generate A CSV file;


3. Generate A new CSV file sheet after sheet and B hasn't affected the content of the

hope to get a great god brothers, because do not to come out next week will be to worship...

CodePudding user response:

Sub gen_csv ()
ThisWorkbook. ActiveSheet. SaveAs ThisWorkbook. ActiveSheet. Name + "CSV", 6
End Sub

Whether very simple

CodePudding user response:

Good, remember to oh thank you

CodePudding user response:

Little brother I try ha ~ thanks!

CodePudding user response:

Don't forget to change the file containing the macro to XLSM or XLS format

CodePudding user response:

Hi, too simple, the reply before the estimated using inconvenient, I updated, could use a little better,
Sub gen_csv ()
Dim the cw, cs, CSV As String
Dim reopenwk As Workbook
The cw=ThisWorkbook. FullName
Cs=ThisWorkbook. ActiveSheet. Name
CSV=ThisWorkbook. Path + "" + ThisWorkbook ActiveSheet. Name + "CSV"
ThisWorkbook. ActiveSheet. SaveAs CSV, 6
ThisWorkbook. Saved=True
The Set reopenwk=Workbooks. Open (the cw)
Reopenwk. Worksheets (cs). Activate
ThisWorkbook. Close
End Sub

By the way, before using, had better make a backup,
  • Related