我正在尝试使用以下代码将文件重命名abcd.xls
为xyz.xlsx
-
NumOfAttachments = Range("RecCount").Value
DestinationFolderPath = Range("destinationfolder").Value
NewShtName = "Sheet1"
If NumOfAttachments <> 0 Then
For X = 0 To NumOfAttachments - 1
OrigName = Range("Startcell").Offset(X, 1).Value
NewName = Range("startcell").Offset(X, 2).Value
SourceFolderPath = Range("startcell").Offset(X, 3).Value
NewFile = DestinationFolderPath & NewName
If Dir(DestinationFolderPath & OrigName) <> "" Then Kill DestinationFolderPath & OrigName
FileCopy SourceFolderPath & OrigName, DestinationFolderPath & OrigName
If Dir(NewFile) <> "" Then Kill NewFile
Name DestinationFolderPath & OrigName As NewFile
在此之后,当我尝试打开文件(xyz.xlsx
)时,我收到以下错误 -
excel cannot open the file xyz.xlsx because the file format or file extension is not valid