'文件夹内新建一工作簿将下列代码拷贝到模块中,关闭工作簿,
'再打开工作簿在菜单栏上有“保存CSV文件”,点击后将sheet2表批量生成CSV文件。
Sub SaveText1()
Dim File As String
wj = Dir(ThisWorkbook.Path & "\*.xls")
For i = 1 To 500 '根据文件数量
Workbooks.Open ThisWorkbook.Path & "\" & wj
x = Len(wj)
x = x - 4
wj = Left(wj, x)
File = ThisWorkbook.Path & "\" & wj & ".csv"
On Error Resume Next
Kill File '将原同名文件删除
Worksheets("Sheet2").Select
ActiveWorkbook.SaveAs Filename:=File, FileFormat:=xlCSV
ActiveWorkbook.Close SaveChanges:=False
If wj = "" Then End
wj = Dir
Next
End Sub
Sub auto_open()
MenuBars(xlWorksheet).Reset
Set mycommandbar = CommandBars("standard")
Set mybutton = mycommandbar.Controls.Add(Type:=msoControlButton)
With mybutton
.Style = msoButtonCaption
.Caption = "保存CSV文件"
.Enabled = True
.OnAction = "SaveText1"
End With
End Sub
Sub auto_close()
Set mycommandbar = CommandBars("standard")
For Each mybutton In mycommandbar.Controls
If mybutton.Caption = "保存CSV文件" Then mybutton.Delete
Next
End Sub
好像你要把SHEER2另存到一边。。