User to select variable folder for saving files

nikki_k

New Member
Joined
Jun 5, 2009
Messages
12
Hi I hope someone can help.

I've searched through other posts but either can't find the same scenario as mine or I'm not looking properly. :confused:

I would like my macro to prompt the user to select a folder for files to be either opened from or saved to during the running of my macro.

In fact, I need them to select two folders, one for this month and the other for last month.

I think I need to set the two folders as a variable but being fairly new to vba I'm not quite sure how to do this.

Any help would be greatly appreciated. :)

Thanks
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi Nikki & Welcome to the Board!

If you are using xl2002 or above you can use:

Code:
Dim strFolder As String
 
With FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ThisWorkbook.Path
    .AllowMultiSelect = False
    If .Show = -1 Then
        strFolder = .SelectedItems(1)   'selected folder assigned to variable strFolder here
    Else
        MsgBox "No folder selected! Exiting Sub...": Exit Sub
    End If
End With
 
'then use strFolder:
 
ActiveWorkbook.SaveAs strFolder & "\MyFile.xls"    'for example
 
Upvote 0
Oops ... sorry just one more question:

How can I get it to include the strFolder name into the file name when it saves eg:

strFolder is ... C:\Reconciliation\Pension\Jun09

so I want my file name to be 'MyFile Jun09.xls'

Thanks in advance.
 
Upvote 0
He did but it just saves as 'MyFile.xls' and ideally I would like it to save as 'MyFile Jun09.xls'

I can't work out how to add the last folder name to be in the file name.
 
Upvote 0
Here is an example of how to construct the file name:

Code:
Sub Test()
    Const strFolder = "C:\Reconciliation\Pension\Jun09"
    Dim Per As String
    Per = Right(strFolder, Len(strFolder) - InStrRev(strFolder, "\"))
    MsgBox strFolder & "\MyFile " & Per & ".xls"
End Sub
 
Upvote 0
Hi Nikki

Try the following:

Code:
ActiveWorkbook.SaveAs strFolder & "\" & "MyFile " & Mid(strFolder,InstrRev(strFolder,"\")+1) & ".xls"
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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