Select a output folder inside a sell with VBA

carlosanoli

New Member
Joined
Jun 5, 2019
Messages
3
Helo everyone,
I am using this code to unzip files:

Code:
[COLOR=blue][FONT=Raleway]Sub Unzip_Files()[/FONT][/COLOR]
[COLOR=#38761D][FONT=Raleway]' Author: Dreams24[/FONT][/COLOR]
[COLOR=#38761D][FONT=Raleway]' Written for VBA Tricks and tips blog[/FONT][/COLOR]
[COLOR=#38761D][FONT=Raleway]' [URL="https://www.vbatricksntips.com/"]https://www.vbatricksntips.com[/URL][/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]
[/FONT][/COLOR][COLOR=#232323][FONT=Raleway][/FONT][/COLOR][COLOR=#38761D][FONT=Raleway]'Declare Variable[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]    Dim oApp As Object[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]    Dim Fname As Variant[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]    Dim Output_Folder As Variant[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]    Dim strDate As String[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]    Dim i As Long[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]   [/FONT][/COLOR]
[COLOR=#38761D][FONT=Raleway]    'Select multiple zip files to unzip[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]    Fname = Application.GetOpenFilename(filefilter:="Zip Files (*.zip), *.zip", _[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]                                        MultiSelect:=True)[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]    If IsArray(Fname) = False Then[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        'Do nothing[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]    Else[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        [/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        [/FONT][/COLOR][COLOR=#38761D][FONT=Raleway]'Set output folder path for unzip files[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        Output_Folder = "C:\Users\Dreams\Desktop\Test_Unzip\Unzip"[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        [/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        [/FONT][/COLOR][COLOR=#38761D][FONT=Raleway]'Append backslash to output folder path[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        If Right(Output_Folder, 1) <> "" Then[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]            Output_Folder = Output_Folder & ""[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        End If[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]
[/FONT][/COLOR][COLOR=#232323][FONT=Raleway][/FONT][/COLOR][COLOR=blue][FONT=Raleway]       [/FONT][/COLOR][COLOR=#38761D][FONT=Raleway] 'Extract the files into output folder[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        Set oApp = CreateObject("Shell.Application")[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        For i = LBound(Fname) To UBound(Fname)[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]            [/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]            oApp.Namespace(Output_Folder).CopyHere oApp.Namespace(Fname(i)).items[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]
[/FONT][/COLOR][COLOR=#232323][FONT=Raleway][/FONT][/COLOR][COLOR=blue][FONT=Raleway]        Next i[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]
[/FONT][/COLOR][COLOR=#232323][FONT=Raleway][/FONT][/COLOR][COLOR=blue][FONT=Raleway]        MsgBox "You find the files here: " & Output_Folder[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]        [/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]    End If[/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]    [/FONT][/COLOR]
[COLOR=blue][FONT=Raleway]End Sub[/FONT][/COLOR]

But instead of let the output folder inside the code, I would like to put it in a cell where other people could easily change the output. Can someone help me to change this code?

Thanks a lot.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Change this,
Code:
        Output_Folder = "C:\Users\Dreams\Desktop\Test_Unzip\Unzip"
to this.
Code:
        Output_Folder = Sheets("Sheet1").Range("A1").Value ' change sheet/cell reference as required
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top