I tried posting this on the Excel Tech forum but with no luck. So here is the post:
I developed a program that uses the File Open dialog box code on Excel 2016 using VBA. When running the same program on a MAC that is "supposed to run VBA", most of it worked.. except the file, open dialog box.
It works great on a windows machine, but fails on the MAC. I even tried the older version of the code.
Here is the most recent format of the open:
Code: Select all
Private Sub FileDialogueOpenCustomModel()
Application.ScreenUpdating = False
Dim dlgOpenFile As FileDialog
Dim strFullFilePathToModel As String
strFullFilePathToModel = ""
Set dlgOpenFile = Application.FileDialog(msoFileDialogOpen)
With dlgOpenFile
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Excel 2007-2016 Workbook", "*.xlsx"
.FilterIndex = 1
.Title = "Select Custom Model"
.Show
If .SelectedItems.Count < 1 Then
strCancel = "Y"
Exit Sub
End If
strFullFilePathToModel = .SelectedItems(1)
End With
Workbooks.Open strFullFilePathToModel
strCustomModelFileNameOpenedByUser = ActiveWorkbook.Name
End Sub
Here is the OLDER version of that function, that also fails:
Public Sub OpenFileDialogue()
' ************************************************
' Display a File Open Dialogue Box For The User
' ************************************************
strCancel = "N"
strWorkbookNameAndPath = Application.GetOpenFilename _
(FileFilter:=strFilt, _
FilterIndex:=intFilterIndex, _
Title:=strDialogueFileTitle)
' ************************************************
' Exit If No File Selected
' ************************************************
If strWorkbookNameAndPath = "" Then
MsgBox ("No Filename Selected")
strCancel = "Y"
Exit Sub
ElseIf strWorkbookNameAndPath = "False" Then
MsgBox ("You Clicked The Cancel Button")
strCancel = "Y"
Exit Sub
End If
' ******************************************************
' Now That You Have The User Selected File Name, Open It
' ******************************************************
Workbooks.Open strWorkbookNameAndPath
strWorkbookName = ActiveWorkbook.Name
MsgBox ("You Just Opened " & strWorkbookName)
End Sub
Rich Locus