Vba Excel宏以重命名文件扩展名
我对脚本很幼稚,我开始使用Excel宏。我正在寻找一个宏,仅将文件扩展名从*.xml重命名为*.qml。*.xml文件位于同一工作簿路径中。因此,如果有人能在这方面提供帮助,我将不胜感激。请尝试以下代码:Vba Excel宏以重命名文件扩展名,vba,excel,Vba,Excel,我对脚本很幼稚,我开始使用Excel宏。我正在寻找一个宏,仅将文件扩展名从*.xml重命名为*.qml。*.xml文件位于同一工作簿路径中。因此,如果有人能在这方面提供帮助,我将不胜感激。请尝试以下代码: Sub RenameFiles() Dim StrFile As String, newName As String Dim filePath As Variant filePath = ActiveWorkbook.Path & "\" StrFile
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
,因此最好在执行代码之前进行备份。尝试以下代码:
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
,因此最好在执行代码之前备份