【发布时间】:2019-10-11 17:42:44
【问题描述】:
我正在尝试编写一个重命名多个 Excel 文件的脚本。如果文件的名称中有“TEMP”,我想将“TEMP”更改为输入框中的日期。
脚本一直有效,直到我进入 For 循环。我得到一个
需要对象:'C:\users\jspfu\sourc' 第 23 行错误,代码 800A01A8
错误。我对 VBScript 真的很陌生,我基本上从 YouTube 视频中复制了这段代码,无论如何都是 For-loop 部分。
到目前为止,这是我的脚本:
Option Explicit
Dim FSO,FileLoc, UsrDate, Msg, File, Oldname, NewFileName, FoldName
Set FSO = CreateObject("Scripting.FileSystemObject")
FileLoc = "C:\Users\jspfu\source\XL_Files"
UsrDate= Inputbox("Enter the Date", "Date")
FoldName = FSO.GetFolder(FileLoc)
If IsNumeric(UsrDate) and UsrDate<>"" then
Msg = Msgbox ("is this " & UsrDate & " Correct",VBYesNo, "Verify Date")
end if
Do While Msg <> 6
If Msg = 7 Then
UsrDate= Inputbox("Enter the Date", "Date")
Msg = Msgbox ("is this " & UsrDate & " Correct",VBYesNo, "Verify Date")
ElseIf Not IsNumeric(UsrDate) or UsrDate= "" then
UsrDate= Inputbox("Enter the Date", "Date")
End If
Loop
For each File in FoldName.files
Oldname = FileLOC & File.name
NewFileName = replace(Fname, "TEMP", Date)
FSO.MoveFile Fname, NewFileName
Next
感谢您的帮助。
【问题讨论】:
标签: vbscript