msoFileDialogFilePicker Throws Error: object variable with block variable not set

arveearv

New Member
Joined
Apr 29, 2013
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
  2. MacOS
Hi:

I'm trying to use this standard bit of code:

VBA Code:
Dim fd As Office.FileDialog
Dim strFile As String

Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd
    .AllowMultiSelect = False

    If .Show = -1 Then
        strFile = .SelectedItems(1)

    End If

End With

But I'm getting the error message:
object variable with block variable not set

Any idea what might be going wrong? [Note that when I am entering the code, "msoFileDialogFilePicker" does not pop up from the References Library. Is it possible my system is missing this operation? If so, how would I add it to my resources? I'm a newbie to VBA -- please be kind!]


Arv
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
If you do it like this, then you don't need to add any references
VBA Code:
Dim fd As Object
Dim strFile As String

Set fd = Application.FileDialog(3)

With fd
    .AllowMultiSelect = False

    If .Show = -1 Then
        strFile = .SelectedItems(1)

    End If

End With
 
Upvote 0
Thanks, Fluff.

What am I doing wrong?

I pasted your code into a new Module, wrapped it in "Sub/ End Sub" and ran it. I still get a Run Time Error 91 with the message: "Object Variable with Block Variable not set"
 
Upvote 0
Odd, are you doing this on a PC or a Mac?
 
Upvote 0
In that case I'm surprised it got that far, as I don't think that Mac's have FileDialog.
 
Upvote 0
Solution
Oh, I see! OK, it looks like picking files on a Mac is a whole other can of worms.

Are you aware of VBA code that can work on both systems? Maybe a conditional statement to detect the user's system, then 2 versions of code -- one for Mac and one for PC?
 
Upvote 0
Fraid not, as I've never worked with a Mac.
You're best bet would be to start a new thread explaining what you need to do & that it should work on both Mac & PC.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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