【发布时间】:2013-03-25 20:50:32
【问题描述】:
我正在尝试使用以下代码将文件从 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
【问题讨论】:
-
您能edit 发布更多代码吗?我没有看到任何实际重命名文件的内容。 (你知道只是重命名它不会将它从
.xls转换为.xlsx文件,对吗?它仍然是.xls文件。) -
我已经发布了整个代码。谢谢!