Add folder picker replacing file path

Darren77

New Member
Joined
Jun 29, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello all

I have tried and failed to find a solution so have resorted to asking for help. I am trying to swap out the fso.getfolder file path for Application.FileDialog(msoFileDialogFolderPicker) which will determine the file path of the files i want to copy

I hope this make sense - very very new to VBA.
Many thanks


Sub TimePlanLog11()

Dim wb As Workbook
Dim fso As Object, f As Object, ff As Object, f1 As Object

Application.ScreenUpdating = False
Set fso = CreateObject("Scripting.FileSystemObject")

'I want to change this section to be decided by a file picker

Set f = fso.Getfolder("C:\Users\clarkd02\AkzoNobel\Commercial Strategy and Planning - Project Management\Project Tracking\2023 PROJECT TRACKING\2. Grow the Category - Darren\2.3 Worth the Extra")

Set ff = f.Files
For Each f1 In ff
Set wb= Workbooks.Open(f1)

Sheets("TimePlan Log").Range("A3:F15" & Range("F65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(4).Activate
ThisWorkbook.Worksheets(4).Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
wb.Close SaveChanges:=False

Next
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Replace:
VBA Code:
Set f = fso.Getfolder("C:\Users\clarkd02\AkzoNobel\Commercial Strategy and Planning - Project Management\Project Tracking\2023 PROJECT TRACKING\2. Grow the Category - Darren\2.3 Worth the Extra")
with:
VBA Code:
    Dim folderPath As String
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Select folder"
        .InitialFileName = ThisWorkbook.Path
        If .Show Then
            folderPath = .SelectedItems(1) & "\"
        Else
            Exit Sub
        End If
    End With
    Set f = fso.GetFolder(folderPath)
 
Upvote 0
Solution
Replace:
VBA Code:
Set f = fso.Getfolder("C:\Users\clarkd02\AkzoNobel\Commercial Strategy and Planning - Project Management\Project Tracking\2023 PROJECT TRACKING\2. Grow the Category - Darren\2.3 Worth the Extra")
with:
VBA Code:
    Dim folderPath As String
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Select folder"
        .InitialFileName = ThisWorkbook.Path
        If .Show Then
            folderPath = .SelectedItems(1) & "\"
        Else
            Exit Sub
        End If
    End With
    Set f = fso.GetFolder(folderPath)
Amazing, its works perfectly. Thank you so much
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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