我在VBA中有一个函数来检查文件是否存在。如果该文件存在,我需要通过在文件名后连接一个guid来重命名该文件。但是,当我尝试在文件名和文件类型之间添加guid时,它不会保留guid之后的任何内容。例如,如果原始文件名是" test.xlsx",则该函数会将文件重命名为" test {guid}"没有.xlsx。
Sub fileExists()
Dim TypeLib As Object
Dim FilePath As String
Dim NeNewPath As String
Dim guid As String
Set TypeLib = CreateObject("Scriptlet.TypeLib")
guid = TypeLib.guid
guid = Replace(guid, "{", "")
guid = Replace(guid, "}", "")
FilePath = "C:\Users\user\Desktop\excel\test.xlsx"
NewPath = "C:\Users\user\Desktop\excel\test" & guid & ".xlsx"
If Dir(FilePath) <> "" Then
Name FilePath As NewPath
End If
End Sub