?
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
Medium Priority
?
213 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

800 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