VBA (msoFileDialogFolderPicker) Error

VBA learner ITG

Active Member
Joined
Apr 18, 2017
Messages
272
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi all,

I need your advice if possible for some reason I keep getting this error message appearing only on 1 specific macro workbook where it says:

Compile Error:
Cant Find Project or Library

I have the following selected in the reference library and cant understand the cause of the issue!

VBA TOOLS REFERENCE LIBARY.jpg


My Code below for Reference:


VBA Code:
Sub Get_Files_test()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
Dim zFilepath As String
Dim MyRow As Integer

MyRow = InputBox("What Row to start at?")
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
    With Application.FileDialog(msoFileDialogFolderPicker)
    
        .AllowMultiSelect = False
        If .Show = False Then Exit Sub
        zFilepath = .SelectedItems(1)
        DoEvents
    End With
Sheets("Control").Range("E2").Value = zFilepath & "\"
Set objFolder = objFSO.GetFolder(zFilepath)
i = MyRow
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
'print file name
Cells(i, 4) = objFile.Name
'print file path
Cells(i, 5) = objFile.Path
i = i + 1
Next objFile
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Pasted your code in a new workbook. It compiles and runs as intended, so most likely something else is the cause of your issue.

ScreenShot212a.jpg
 
Upvote 0
Pasted your code in a new workbook. It compiles and runs as intended, so most likely something else is the cause of your issue.

hi
Pasted your code in a new workbook. It compiles and runs as intended, so most likely something else is the cause of your issue.

View attachment 45597
Thank you for taking a look. I have unselected and reselected the reference library options and it seems to work.
 
Upvote 0
You could also use
VBA Code:
With Application.FileDialog(4)
which means you would not need to set the reference
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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