注意问题
- window 环境下运行, 代码 ANSI 编码格式保存。
- 直接放到需要转换的文件夹下,双击运行。
代码
function getfolder()
getfolder=left(wscript.scriptfullname,instrrev(wscript.scriptfullname,"")-1)
end function
Call ShowFileList(getfolder())
Sub ShowFileList(folderspec)
Dim fs, f, f1, fc, s, objExcel, tmpname, sourcefile, dstfile, shell, tip
set objExcel = CreateObject("Excel.application")
set fs = CreateObject("Scripting.FileSystemObject")
set f = fs.GetFolder(folderspec)
set fc = f.Files
set shell = CreateObject("WScript.Shell")
fs.createFolder("tmp")
For Each f1 in fc
tmpname = f1.name
if lcase(right(tmpname, 4)) = "xlsx" then
sourcefile = folderspec + "" + f1.name
dstfile = folderspec + " mp" + tmpname
set xslworkbook = objExcel.Workbooks.Open(sourcefile)
For i = 1 to xslworkbook.Sheets.Count
set UseRange1 = xslworkbook.Worksheets(i).UsedRange
UseRange1.Copy
UseRange1.PasteSpecial(-4163)
next
xslworkbook.SaveAs(dstfile)
xslworkbook.close()
tip = tmpname + " complete ..."
WScript.Echo tip
end if
Next
objExcel.close
fs.close
End Sub
VBScript
- 用户手册
- 在线手册
- 语言参考
- 微软官方
- 函数