如何在使用VBA解压文件时更改文件名

如何在使用VBA解压文件时更改文件名,vba,outlook,Vba,Outlook,我正在解压文件夹中的文件,并将其保存到新位置。解压后如何立即重命名该文件?解压后,我将有一个类似1234_data.csv的文件,如何将其重写为whatiwant.csv? 我知道我需要使用一行,例如将oldfile命名为NewFileName Sub Unzip1(str_FILENAME As String) Dim oApp As Object Dim Fname As Variant Dim FnameTrunc As Variant Di

我正在解压文件夹中的文件,并将其保存到新位置。解压后如何立即重命名该文件?解压后,我将有一个类似1234_data.csv的文件,如何将其重写为whatiwant.csv?
我知道我需要使用一行,例如
将oldfile命名为NewFileName

Sub Unzip1(str_FILENAME As String)  
    Dim oApp As Object  
    Dim Fname As Variant  
    Dim FnameTrunc As Variant  
    Dim FnameLength As Long 

    'Fname = str_FILENAME   'Commented out to show example file name
    Fname = "file.zip"  

FnameLength = Len(Fname)  
If Fname = False Then  
    'Do nothing  
    Else  

'Extract the files into the newly created folder  
          Set oApp = CreateObject("Shell.Application")

oApp.NameSpace("C:\Users\Andrew\folder").CopyHere oApp.NameSpace(Fname).Items  
DoEvents  
    End If  

End Sub
基于评论的替代方案

  Sub post_unzip(str_just_unzipped_filename As String, str_new_filename As String)

   str_path = "c:\thepathtothezips\"

   Name strpath + str_just_unzipped_filename As strpath + str_new_filename

  End Sub

谢谢您的回答,但我的文件夹中有多个文件,因此您的代码无法正确覆盖该文件。它必须在最新的文件上执行。
  Sub post_unzip(str_just_unzipped_filename As String, str_new_filename As String)

   str_path = "c:\thepathtothezips\"

   Name strpath + str_just_unzipped_filename As strpath + str_new_filename

  End Sub