当我尝试运行它时,未定义msoFileDIalogFolderPicker时显示错误。我已经检查了对Office 14库的引用,但仍然无法正常工作?
Dim MyFolder As String 'Path collected from the folder picker dialog
Dim MyFile As String
Dim wbk As Workbook
On Error Resume Next
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFolderPicker)
答案 0 :(得分:1)
我没有Mac,但请参考(https://www.rondebruin.nl/mac/mac017.htm),尝试以下操作(您可能需要在某些地方进行调整),看看它是否满足您的要求:
Sub Select_Folder_On_Mac()
Dim folderPath As String
Dim RootFolder As String
Dim scriptstr As String
On Error Resume Next
RootFolder = MacScript("return (path to desktop folder) as String")
'Or use RootFolder = "Macintosh HD:Users:YourUserName:Desktop:TestMap:"
'Note : for a fixed path use : as seperator in 2011 and 2016
If Val(Application.Version) < 15 Then
scriptstr = "(choose folder with prompt ""Select the folder""" & _
" default location alias """ & RootFolder & """) as string"
Else
scriptstr = "return posix path of (choose folder with prompt ""Select the folder""" & _
" default location alias """ & RootFolder & """) as string"
End If
folderPath = MacScript(scriptstr)
On Error GoTo 0
If folderPath <> "" Then
MsgBox folderPath
End If
End Sub