Excelmacros来重命名文件扩展名

我天真的脚本,我开始使用Excelmacros。 我正在寻找一个macros,只将文件扩展名从* .xml重命名为* .qml。 * .xml文件位于相同的工作簿path中。 所以,如果有人能够帮助,我很感激。

尝试下面的代码:

Sub RenameFiles() Dim StrFile As String, newName As String Dim filePath As Variant filePath = ActiveWorkbook.Path & "\" StrFile = Dir(filePath & "*.xml") Do While Len(StrFile) > 0 newName = Replace(StrFile, ".xml", ".qml") Name filePath & StrFile As filePath & newName StrFile = Dir Loop End Sub 

注意 :代码会将所有.xml文件重命名为.qml因此最好在执行代码之前进行备份。