how to run Application.FileDialog(msoFileDialogOpen) vba code in mac on office 365

Ravish Agrawal 0 Reputation points
2023-04-05T14:39:02.8333333+00:00

how to run Application.FileDialog(msoFileDialogOpen) vba code in mac office 365 when i run on windows it works perfect but on mac it shows error 91 block variable not set. my code is under. can you help me

sub aaa()
Dim myFileDialog As Office.FileDialog
Set myFileDialog = Application.FileDialog(msoFileDialogOpen)
myFileDialog.AllowMultiSelect = False
myFileDialog.Title = " Select a Bank Statement file to open "

If myFileDialog.Show = -1 Then
    'Get the file name and path
    fna = myFileDialog.SelectedItems(1)
    'Open the file
  Set wb = Workbooks.Open(fna)
  Else
    MsgBox " You chose to quit"
    Exit Sub
End If
msgbox wb.Sheets(1).Range("D3").value
end sub
Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Install, redeem, activate | For business | MacOS
Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. John Korchok 6,416 Reputation points Volunteer Moderator
    2023-04-05T17:25:36.93+00:00

    To open built-in dialogs in Office for Mac VBA, you'll have to use the MacScript command. Please see the answer on this page for an example: https://answers.microsoft.com/en-us/msoffice/forum/all/showing-dialogs-word-for-mac-vba/513ea974-378d-4ebe-95c3-a0221a9287ff

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.