Excel VBA has written a macro to bulk export table data in Excel to CSV format files

Source: Internet
Author: User

Sub CSV ()
Dim Fs, MyFile as Object
Dim myfileline as String ' txtfile row data
Dim Sht as Worksheet

For each sht in Thisworkbook.sheets
NS = Sht. Cells (1, 8)
Set Fs = CreateObject ("Scripting.FileSystemObject") ' established Filesytemobject
Set myFile = fs.createtextfile (Activeworkbook.path + "\csv\" + ns + ". csv") ' Create a new TXT file with the same name as the XLS file by FileSystemObject
For i = 2 to 1000
RA = sht. Cells (i, 3)
If ra = "Then Exit for"
RB = ""
For j = 3 to 1000
CA = Sht. Cells (2, J)
If CA = "Then Exit for
If RB = "Then"
RB = Sht. Cells (i, J). Value
Else
RB = RB & "," & Sht. Cells (i, J). Value
End If
Next J
MyFile.WriteLine (RB)
Next I
Set MyFile = Nothing
Set Fs = Nothing ' Close file and FileSystemObject object
Next
End Sub

Excel VBA has written a macro to bulk export table data in Excel to CSV format files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.