Solved

How do I change this VBA code to reference the data in a cell instead of the fixed path?

Posted on 2014-07-31
4
212 Views
Last Modified: 2014-08-03
I’m need to change the source of the file from this:
Call UnZip("C:\Users\NC\Desktop\Vishesh\Test", "C:\Users\NC\Desktop\Vishesh\Test\TestZipFile.Zip")

To:
Range("D12") in work sheet "Main Menu", Zip file name: "TestZipFile)


Sub TestRun()
 
    'Change this as per your requirement

    Call UnZip("C:\Users\NC\Desktop\Vishesh\Test", "C:\Users\NC\Desktop\Vishesh\Test\TestZipFile.Zip")
 
End Sub
 
 
 
Sub UnZip(strTargetPath As String, Fname As Variant)
 
    Dim oApp As Object
 
    Dim FileNameFolder As Variant
 
 
 
    If Right(strTargetPath, 1) <> Application.PathSeparator Then
 
        strTargetPath = strTargetPath & Application.PathSeparator
 
    End If
 
 
 
    FileNameFolder = strTargetPath
 
 
 
    Set oApp = CreateObject("Shell.Application")
 
    oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname).items
 
End Sub

Open in new window

0
Comment
Question by:kbay808
[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
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40233187
If D12 only has the file name then change line 5 to this:
 Call UnZip("C:\Users\NC\Desktop\Vishesh\Test", "C:\Users\NC\Desktop\Vishesh\Test\" & Sheets("Main Menu").Range("D12").Value & ".zip")

Open in new window


You could make this a little easier to handle by assigning the filepath to a variable and using that in the statement like so:
Dim strFilePath as String
strFilePath = "C:\Users\NC\Desktop\Vishesh\Test"
Call UnZip(strFilePath, strFilePath & Sheets("Main Menu").Range("D12").Value & ".zip")

Open in new window


Regards,
-Glenn
0
 

Author Comment

by:kbay808
ID: 40233419
My question must be misleading.  I currently have a button for the user to click that will allow the user to use a windows explorer to navigate to the folder.  That path is then populated into cell D12.  I need to modify the code to accept the path given in D12.  The zip file will always be the same.

Example:
Path= Range (“D12”)
Filename= “TestZipFile.Zip”
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40233438
Okay, here's the modified code for what you described:
Dim strFilePath as String
strFilePath = Sheets("Main Menu").Range("D12").Value
Call UnZip(strFilePath, strFilePath & "TestZipFile.zip")

Open in new window


Hope that helps!
-Glenn
0
 

Author Closing Comment

by:kbay808
ID: 40237069
Thank you very much
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

696 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