将Excel转换为CSV的VBA代码
1 Attribute VB_Name = "模块1"
2 Sub Macro1()
3 Attribute Macro1.VB_Description = " "
4 Attribute Macro1.VB_ProcData.VB_Invoke_Func = " \n14"
5 '
6 ' Macro1 Macro
7 ' 宏由 Eric yang 录制,时间:
8 '
9
10 '
11 ChDir "D:\"
12
13 cDir = "D:\"
14
15 Do While True
16
17 FName = InputBox("请输入要转换的文件名:", "转换到CSV")
18
19 If FName = "" Then
20 Exit Sub
21 End If
22
23 Workbooks.Open Filename:=cDir & FName & ".xls"
24
25 ActiveWorkbook.SaveAs Filename:=cDir & FName & ".csv", FileFormat:=xlCSV, _
26 CreateBackup:=False
27
28 ActiveWindow.Close SaveChanges:=-1
29
30 Loop
31
32 End Sub
33
2 Sub Macro1()
3 Attribute Macro1.VB_Description = " "
4 Attribute Macro1.VB_ProcData.VB_Invoke_Func = " \n14"
5 '
6 ' Macro1 Macro
7 ' 宏由 Eric yang 录制,时间:
8 '
9
10 '
11 ChDir "D:\"
12
13 cDir = "D:\"
14
15 Do While True
16
17 FName = InputBox("请输入要转换的文件名:", "转换到CSV")
18
19 If FName = "" Then
20 Exit Sub
21 End If
22
23 Workbooks.Open Filename:=cDir & FName & ".xls"
24
25 ActiveWorkbook.SaveAs Filename:=cDir & FName & ".csv", FileFormat:=xlCSV, _
26 CreateBackup:=False
27
28 ActiveWindow.Close SaveChanges:=-1
29
30 Loop
31
32 End Sub
33