Extracting an Excel file from a zip folder using Access VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ChrisSpencer
    New Member
    • Feb 2010
    • 2

    Extracting an Excel file from a zip folder using Access VBA

    I had the following line of code working to extract an Excel lfile from a temp.zip folder, but it stopped working about 2 months ago.

    Set oApp = CreateObject("S hell.Applicatio n")
    oApp.Namespace( ZipFilePath).Co pyHere (ZipFilePath & "temp.zip\" & ExcelFileName)

    The error message is "The file exists". Can anyone suggest why this would suddenly stop working? I am not sure what settings might have changed, but updates get rolled out in my company with users knowing.
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Looks like the overwrite stopped working, or your filename was different each time in the past.
    When the file does exist, you can delete it before unzipping it by using the KILL command.
    With the Dir() function you could check or the file name is already in present.

    Nic;o)

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      To Unzip Test.xls, contained within Test.zip, the C:\Zips\ Folder to the C:\UnZips\ Folder as Test.xls:
      Code:
      Const conPATH_TO_ZIP_FILE As String = "C:\Zips\Test.zip"
      Const conUNZIPPED_PATH As String = "C:\UnZips\"
      Const conFILE_NAME As String = "Test.xls"
      Dim oApp As Object
      
      If Dir$(conUNZIPPED_PATH & conFILE_NAME) <> "" Then
        Kill conUNZIPPED_PATH & conFILE_NAME
      
        Set oApp = CreateObject("Shell.Application")
      
        oApp.Namespace(conUNZIPPED_PATH).CopyHere _
        oApp.Namespace(conPATH_TO_ZIP_FILE).Items.Item(conFILE_NAME)
      End If

      Comment

      • ChrisSpencer
        New Member
        • Feb 2010
        • 2

        #4
        Originally posted by ADezii
        To Unzip Test.xls, contained within Test.zip, the C:\Zips\ Folder to the C:\UnZips\ Folder as Test.xls:
        Code:
        Const conPATH_TO_ZIP_FILE As String = "C:\Zips\Test.zip"
        Const conUNZIPPED_PATH As String = "C:\UnZips\"
        Const conFILE_NAME As String = "Test.xls"
        Dim oApp As Object
        
        If Dir$(conUNZIPPED_PATH & conFILE_NAME) <> "" Then
          Kill conUNZIPPED_PATH & conFILE_NAME
        
          Set oApp = CreateObject("Shell.Application")
        
          oApp.Namespace(conUNZIPPED_PATH).CopyHere _
          oApp.Namespace(conPATH_TO_ZIP_FILE).Items.Item(conFILE_NAME)
        End If
        I tried copying your code exactly and I am still having problems. I can extract the excel file from a regular folder, but it gives me the error message when I try to extract from a zip folder.
        The frustrating part is this worked fine for me a few months ago and then suddenly stopped around Christmas. I am wondering if a setting has changed on my computer or Access references.

        Comment

        Working...