码迷,mamicode.com
首页 > 其他好文 > 详细

excel 批量格式转换

时间:2016-06-21 12:32:25      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

脚本运行方式

在需要转换的csv或者xls同目录新建一个xls文件,alt+f11打开VBA project,然后将代码贴入,点击运行即可。

XLS批量转换为CSV

Sub xls2csv()
	Application.DisplayAlerts = False
	t = ActiveWorkbook.Name
	mypath = ActiveWorkbook.Path & "\"
	myfile = Dir(mypath & "*.xls")
	Do Until Len(myfile) = 0
		If myfile <> t Then
			Workbooks.Open Filename:=mypath & myfile
			ActiveWorkbook.SaveAs Filename:=mypath & Left(myfile, InStr(myfile, ".") - 1) & ".csv", FileFormat:=xlCSV
		End If
		If myfile <> t Then ActiveWorkbook.Close
		myfile = Dir
	Loop
	Application.DisplayAlerts = True
End Sub

CSV批量转XLS

Sub xls2csv()
	Application.DisplayAlerts = False
	t = ActiveWorkbook.Name
	mypath = ActiveWorkbook.Path & "\"
	myfile = Dir(mypath & "*.csv")
	Do Until Len(myfile) = 0
		If myfile <> t Then
			Workbooks.Open Filename:=mypath & myfile
			ActiveWorkbook.SaveAs Filename:=mypath & Left(myfile, InStr(myfile, ".") - 1) & ".xls", FileFormat:=xlExcel8
		End If
		If myfile <> t Then ActiveWorkbook.Close
		myfile = Dir
	Loop
	Application.DisplayAlerts = True
End Sub

  

如有疑问,请留言。

excel 批量格式转换

标签:

原文地址:http://www.cnblogs.com/cise/p/5603149.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!