Solved

Unzipping

Posted on 2015-01-06
8
159 Views
Last Modified: 2015-01-07
Hi Experts,

I have one WB with VBA code in it, which downloads files from WEB. I am looking the code for  6th button "BSE Equity".
this button download file and save to "D:\AmiBroker Data\BSE\Eq" as zip, I need to add some steps which unzip those files via Code.

See attached

Thanks
Incoporated-Download-File-V02.xlsm
0
Comment
Question by:itjockey
  • 5
  • 2
8 Comments
 
LVL 2

Assisted Solution

by:Pratik Makwana
Pratik Makwana earned 25 total points
ID: 40534981
Use below code...
Sub ProcessFile()
    Dim SourcePath As String, Filename As String

    SourcePath = "D:\AmiBroker Data\BSE\Eq\"

    Filename = Dir(SourcePath)

    Do While Len(Filename) > 0
        If Right(Filename, 3) = "zip" Then
        Call UnZipFile(SourcePath, Filename)
        Kill SourcePath & Filename
        End If
        Filename = Dir()
    Loop
End Sub

Sub UnZipFile(strTargetPath As String, Fname As String)
    Dim oApp As Object
    Dim FileNameFolder As Variant

    If Right(strTargetPath, 1) <> Application.PathSeparator Then
        strTargetPath = strTargetPath & Application.PathSeparator
    End If

    FileNameFolder = strTargetPath
    dPath = "D:\AmiBroker Data\BSE\Eq\"
    Set oApp = CreateObject("Shell.Application")
    On Error Resume Next
    oApp.Namespace(dPath).CopyHere oApp.Namespace(FileNameFolder & Fname).Items
    On Error GoTo 0
End Sub

Open in new window

0
 
LVL 29

Accepted Solution

by:
gowflow earned 475 total points
ID: 40535168
ok here it is in the attached file it has the following updated from last version:

1) Included access to unzip all files shown in the said directory on the BSE Equity activation.

2) Included a WARNING messagebox just prior deleting files. I believe this is mandatory just letting you know what directory it will delete files from (In case for some reason the variable have not been initialized correctly you are at least warned before deleting files in this directory) As you know there is a routine that delete all files in the said directory just prior to activation of the routine. and in the past for wrong initialization it had deleted files from a wrong location which is something we do not want to happen. I know you don't like message boxes but this one is a MUST !

3) Included now a TRACE (if trace is selected) to show that files are being unzipped and this routine is being accessed.

Pls check the version and let me know.
gowflow
Incoporated-Download-File-V03.xlsm
0
 
LVL 8

Author Comment

by:itjockey
ID: 40535603
Pratik Bhai,

Not so familiar with VBA Coding may be your code is work fine, but I don't know how to implement.

Thanks
0
 
LVL 8

Author Comment

by:itjockey
ID: 40535632
Sir.Gowflow,

Downloading and unzipping work perfect.
Thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Author Closing Comment

by:itjockey
ID: 40535637
Thanks & Perfect.
0
 
LVL 8

Author Comment

by:itjockey
ID: 40535640
May I ask follow up?
0
 
LVL 29

Expert Comment

by:gowflow
ID: 40535730
yes for sure
gowflow
0
 
LVL 8

Author Comment

by:itjockey
ID: 40535778
Here It Is.

Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

My experience with Windows 10 over a one year period and suggestions for smooth operation
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

911 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

23 Experts available now in Live!

Get 1:1 Help Now