怎么将文件夹中的excel文件批量转换成同名的csv文件,txt制表分隔符格式的文件,求宏代码及制作方法
答案:1 悬赏:80 手机版
解决时间 2021-01-29 04:04
- 提问者网友:溺爱和你
- 2021-01-28 14:09
怎么将文件夹中的excel文件批量转换成同名的csv文件,txt制表分隔符格式的文件,求宏代码及制作方法
最佳答案
- 五星知识达人网友:大漠
- 2021-01-28 15:45
制表分隔符格式的文件不是csv扩展名的.
csv扩展名的文件是以逗号分隔的.
txt扩展名的文件是以制表分隔符分隔的.
存为csv 和txt 的代码我都给你你 看需要吧
在要转换的目录新建一个excel文件.
打开这个新的excel文件
ALT+F11进入vba编辑窗口 新建一个模块 粘贴以下代码.
存为制表分隔符的文件
Sub 转换TXT()
Dim FilePath, MyFile, iPath As String
iPath = ThisWorkbook.Path
MyFile = Dir(iPath & "\*.xls")
If MyFile <> "" Then
Do
On Error Resume Next
If MyFile = ThisWorkbook.Name Then MyFile = Dir
Workbooks.Open (iPath & "\" & MyFile)
MyFile = Replace(MyFile, ".xls", ".txt")
Name = "\" & MyFile
FilePath = iPath & Name
ActiveWorkbook.SaveAs Filename:=FilePath, FileFormat:= _
xlText, CreateBackup:=False
Workbooks(MyFile).Close True
MyFile = Dir
Loop While MyFile <> ""
End If
End Sub
Sub 转换CSV()
Dim FilePath, MyFile, iPath As String
iPath = ThisWorkbook.Path
MyFile = Dir(iPath & "\*.xls")
If MyFile <> "" Then
Do
On Error Resume Next
If MyFile = ThisWorkbook.Name Then MyFile = Dir
Workbooks.Open (iPath & "\" & MyFile)
MyFile = Replace(MyFile, ".xls", ".csv")
Name = "\" & MyFile
FilePath = iPath & Name
ActiveWorkbook.SaveAs Filename:=FilePath, FileFormat:= _
xlCSV, CreateBackup:=False
Workbooks(MyFile).Close True
MyFile = Dir
Loop While MyFile <> ""
End If
End Sub
csv扩展名的文件是以逗号分隔的.
txt扩展名的文件是以制表分隔符分隔的.
存为csv 和txt 的代码我都给你你 看需要吧
在要转换的目录新建一个excel文件.
打开这个新的excel文件
ALT+F11进入vba编辑窗口 新建一个模块 粘贴以下代码.
存为制表分隔符的文件
Sub 转换TXT()
Dim FilePath, MyFile, iPath As String
iPath = ThisWorkbook.Path
MyFile = Dir(iPath & "\*.xls")
If MyFile <> "" Then
Do
On Error Resume Next
If MyFile = ThisWorkbook.Name Then MyFile = Dir
Workbooks.Open (iPath & "\" & MyFile)
MyFile = Replace(MyFile, ".xls", ".txt")
Name = "\" & MyFile
FilePath = iPath & Name
ActiveWorkbook.SaveAs Filename:=FilePath, FileFormat:= _
xlText, CreateBackup:=False
Workbooks(MyFile).Close True
MyFile = Dir
Loop While MyFile <> ""
End If
End Sub
Sub 转换CSV()
Dim FilePath, MyFile, iPath As String
iPath = ThisWorkbook.Path
MyFile = Dir(iPath & "\*.xls")
If MyFile <> "" Then
Do
On Error Resume Next
If MyFile = ThisWorkbook.Name Then MyFile = Dir
Workbooks.Open (iPath & "\" & MyFile)
MyFile = Replace(MyFile, ".xls", ".csv")
Name = "\" & MyFile
FilePath = iPath & Name
ActiveWorkbook.SaveAs Filename:=FilePath, FileFormat:= _
xlCSV, CreateBackup:=False
Workbooks(MyFile).Close True
MyFile = Dir
Loop While MyFile <> ""
End If
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯