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

时间:2016-01-25 15:07:29

标签: vba outlook-vba

我正在解压缩文件夹中的文件,并保存在新位置。解压缩后如何立即重命名该文件?解压后我会有一个像1234_data.csv这样的文件,如何将其重写为whatiwant.csv?
我知道我需要使用Name oldfile As 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

1 个答案:

答案 0 :(得分:1)

  strPath = “c:\tempzips\”
  Fname = "new_file_name.zip"  

  If Len(Fname) Then  

    Name strPath + "original.zip" As strPath + Fname

  End If  

根据评论替代

  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