I have a function in VBA to check whether a file exists. If the file exists, I need to rename the file by concatenating a guid after the file name. However, when I try to add the guid between the file name and file type, it will not keep anything that comes after the guid. For example, if the original file name is "test.xlsx", the function will rename the file to "test{guid}" without the .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