Share via

Unable to use msoFileDialogFolderPicker

Anonymous
2021-11-11T13:22:31+00:00

Hello,

I am new to Excel VBA, and I am trying to make a shared folder in excel, but on running the code mentioned below, I am getting "Run-Time Error '91' Object variable or With block variable not set"

I am running O360 on a mac. The code is as follows:

Sub Admin_BrowseForAppFolder()

Dim AppFolder As FileDialog

Set AppFolder = Application.FileDialog(msoFileDialogFolderPicker)

With AppFolder

 .AllowMultiSelect = False

 .Title = "Please select a folder"

 If .Show <> -1 Then GoTo NoSelection

 Admin.Range("N8").Value = .SelectedItems(1) 

NoSelection:

End With

End Sub

Very much appreciate the help of the community.

Thanks,

Akhil N

Microsoft 365 and Office | Excel | For home | MacOS

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2021-11-11T14:34:53+00:00

Hello Akhil,

The msoFileDialogFolderPicker object in a Mac might be different in operation from windows because of the different directory structures of the two OS . You will have to apply different techniques to be able to achieve what you want.

if you visit the link..

https://macexcel.com/examples/filesandfolders/s...

..you will see how accessing the folder structure in a mac comes into play and get some insights on how to access a folder with VBA on a MAC.. please note that the link is a non-Microsoft site, watch out for any advertisements and understand the risks before sharing any personal information on the site.

Kind regards.

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

Answer accepted by question author

Andreas Killer 144.1K Reputation points Volunteer Moderator
2021-11-11T15:09:34+00:00

In addition, you can use a conditional compilation to make the file compatible to both platforms in order to run a different code on each.

Andreas.

#If Mac Then

Sub Admin_BrowseForAppFolder()
'Mac version
End Sub

#Else

Sub Admin_BrowseForAppFolder()
'Windows version
End Sub

#End If

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2021-11-12T09:26:38+00:00

    Thank you so much, that is really useful.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2021-11-12T09:26:16+00:00

    Thank you so much, it did work for me.

    Was this answer helpful?

    0 comments No comments