无法在VBA中的字符串之间连接guid

时间:2017-05-25 12:50:18

标签: excel vba excel-vba

我在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

0 个答案:

没有答案