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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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 …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

623 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