1

This code lets the user select multiple files to open. That last line works okay on my PC, but my remote user tells me that on his Mac it gives an error Run-Time error 91: Object variable or block variable not set

Sub OpenSeveralFiles()
Dim fd As FileDialog
Dim FileChosen As Integer
Dim fileName As String
Dim i As Integer

Set fd = Application.FileDialog(msoFileDialogFilePicker)

fd.InitialView = msoFileDialogViewList

It's odd because I'd expect that error to occur at the Set line.

Could it have something to do with the fact that I don't specify a directory path? In Windows VBA it defaults to a CurDir, but I don't know what happens on a Mac.

Shawn V. Wilson
  • 1,002
  • 3
  • 17
  • 42
  • AFAIK, you can't use `FileDialog` on a Mac: https://stackoverflow.com/questions/37410565/saveas-function-works-on-microsoft-pc-but-not-on-mac/37411960#37411960 – Rory Jul 19 '18 at 08:32
  • If that's true, is there a way to select one or more files? I need the user to open a few files and run another macro on each one. – Shawn V. Wilson Jul 19 '18 at 15:39

1 Answers1

0

If @Rory is correct and I just can't use FileDialog on the Mac, I found a workaround. I warned my user that if he's using a Mac, he'll have to open the files he wants processed before he runs the macro:

On Error resume next
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
On Error goto 0

If fd is not Nothing
    'select and process the files like I did before
Else
    ' Loop through all the OPEN files and process them
End If
Shawn V. Wilson
  • 1,002
  • 3
  • 17
  • 42
  • 1
    Two things you should know if you need to code for Macs: http://www.rondebruin.nl/mac.htm and conditional compilation: `#If Mac Then` – Rory Jul 20 '18 at 07:46