Solved

1) How can I use VBA to unpack a file from a zipfile that gets created in a known file system location?

Posted on 2012-03-21
4
445 Views
Last Modified: 2012-03-25
Hello,

I would like to write a script that will automatically unpack a file from a zipfile that gets created in a known file system location?  There is a new zipfile written out every day.  The underlying data is variable length (some records have more fields than others, but there are fields that are common to every record)text records that are delimited by a "|".  


For example, the day 1 file will be called: abc1.dat.zip
the day 2 file will be called:  abc2.dat.zip

The file could be written out to its own file OR appended to a master text file that includes all the unpacked files.  However, I WOULD NOT want each days file to overwrite the previous days file

The folder location is  "MYFOLDER"
The initial file name is "abc1.dat.zip" and will be incremented by 1 each day.

Thanks!

ps.  We are in a windows environment and eventually these files will be combined together and linked to Access 2007 OR loaded into microsoft access (appended to the ABC table (which will be all of the files appended together (abc1 + abc2 + abc3, etc.)
0
Comment
Question by:pls123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 14

Expert Comment

by:Bill Ross
ID: 37752094
Hi,

What unzip processor are you using?

Bill
0
 

Author Comment

by:pls123
ID: 37752624
I am not sure.  Is there a native unzip processor for windows?  I would imagine that it would be that.
0
 
LVL 6

Assisted Solution

by:wshark83
wshark83 earned 200 total points
ID: 37752831
check this site has useful information and macros

unzip using default windows zup utility --> http://www.rondebruin.nl/windowsxpunzip.htm
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 300 total points
ID: 37753498
Hey,

You'll need a reference to Microsoft Office 1x.0 Object Library, and then the following code, adapted from the link that wshark43 supplied (which is for Excel) is tested and working

Sub UnzipTo(DefPath As String)
    Dim FSO As Object
    Dim oApp As Object
    Dim Fname As Variant
    Dim FileNameFolder As Variant
    Dim fd As FileDialog
    
    'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    'Declare a variable to contain the path
    'of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant
    
    'Use a With...End With block to reference the FileDialog object.
    With fd
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewDetails
        .Title = "Zip Selector"
        'Put a path in here and it will open to the right spot
        .InitialFileName = ""
        .ButtonName = "Unzip"
    
        If .Show = True Then
            'Destination folder
            'DefPath = "C:\Users\Ron\test\"    '<<< Change path
            If Right(DefPath, 1) <> "\" Then
                DefPath = DefPath & "\"
            End If
    
            FileNameFolder = DefPath
            vrtSelectedItem = .SelectedItems(1)
    
            '        'Delete all the files in the folder DefPath first if you want
            '        On Error Resume Next
            '        Kill DefPath & "*.*"
            '        On Error GoTo 0
    
            'Extract the files into the Destination folder
            Set oApp = CreateObject("Shell.Application")
            oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(vrtSelectedItem).Items
    
            MsgBox "You find the files here: " & FileNameFolder
    
            On Error Resume Next
            Set FSO = CreateObject("scripting.filesystemobject")
            FSO.DeleteFolder Environ("Temp") & "\Temporary Directory*", True
        End If
    End With
End Sub

Open in new window


Working sample attached
unzip.mdb
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question