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
434 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
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The viewer will learn how to dynamically set the form action using jQuery.

939 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now