0
我有一个功能可以在Mac(Excel 2015)上打开文件选取器对话框并返回路径。代码如下,但我认为路径是问题,而不是代码,我没有Mac来自己调试它。该函数返回的路径是:Excel VBA - 在Mac上找不到文件
SSD:用户:用户名:下载:时间表出口(40).csv格式
我修改为:用户名:但它正确地显示用户。该文件确实在此位置上,我要求用户发送我的路径和他们派:
/用户/用户名/下载/时间表出口(40).csv格式
Function GetFileMac()
Dim myPath As String
Dim myScript As String
Dim myFiles As String
Dim mySplit As Variant
Dim n As Long
Dim fName As String
Dim myBook As Workbook
On Error Resume Next
myPath = MacScript("return (path to documents folder) as String")
myScript = _
"set applescript's text item delimiters to "","" " & vbNewLine & _
"set theFiles to (choose file of type " & _
" {""com.microsoft.excel.xls"",""public.comma-separated-values-text""} " & _
"with prompt ""Please select the time sheet file"" default location alias """ & _
myPath & """ multiple selections allowed false) as string" & vbNewLine & _
"set applescript's text item delimiters to """" " & vbNewLine & _
"return theFiles"
myFiles = MacScript(myScript)
On Error GoTo 0
If myFiles <> "" Then
mySplit = Split(myFiles, ",")
GetFileMac = mySplit(0)
End If
End Function
当我跑,我得到错误1004文件中没有发现,但上面的路径所提到的回升,是在FP串可用:
Dim fp as string
' if user on Mac etc... then
fp = GetFileMac
Set someWorkbook = Application.Workbooks.Open(fp) ' error here