我修改了一个 vbscript 和批处理文件,它允许我将当前目录中的 HTML 文件转换为 xlsx 文件,如下所示
脚本:
if WScript.Arguments.Count < 2 Then
WScript.Echo "Please specify the source and the destination files"
Wscript.Quit
End If
xlsx_format = 51
Set objFSO = CreateObject("Scripting.FileSystemObject")
src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(1))
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(src_file)
oBook.SaveAs dest_file, xlsx_format
oBook.Close False
oExcel.Quit
Run Code Online (Sandbox Code Playgroud)
批处理文件:
FOR /f "delims=" %%i IN ('DIR *.HTM* /b') DO to-xlsx.vbs "%%i" "%%~ni.xlsx"
del *.HTM /q
Run Code Online (Sandbox Code Playgroud)
通过包含/s在批处理文件中,我可以转换子文件夹中的文件,但它们仍保存在父目录中,我无法弄清楚如何更改它?
src_file是C:\Converter\Subfolder\FileName并且dest_file …
我在单击命令按钮下有一小段代码,该代码将工作簿文件以新名称保存在新位置,我想知道是否也可以在不同位置自动创建新保存的工作簿的快捷方式?
Private Sub CommandButton1_Click()
Dim SelectedFNumber As String
Dim DateStr As String
Dim myFileName As String
Dim StorePath As String
DateStr = Format(Now, "dd.mm.yy HH.mm")
SelectedFNumber = Range("B4").Text
If SelectedFNumber <> "SELECT F NUMBER" And Range("D11") > "0" Then
StorePath = "G:\Targets\" & SelectedFNumber & "\"
myFileName = StorePath & SelectedFNumber & " " & DateStr & ".xlsm
If Len(Dir(StorePath, vbDirectory)) = 0 Then
MkDir StorePath
End If
ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Else
MsgBox "Select an F Number"
End If
End …Run Code Online (Sandbox Code Playgroud)