我有一个在Mac上打开文件选择器对话框的功能(Excel 2015)并返回路径。代码如下,但我认为路径是问题,而不是代码,我自己没有Mac来调试它。函数返回的路径是:
SSD:用户:用户名:下载:timesheet-export(40).csv
我修改了:UserName:但它正确显示了show用户。该文件确实存在于此位置,我要求用户向我发送路径并发送:
/ Users / UserName / Downloads / timesheet-export(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
答案 0 :(得分:1)
您可能需要更改路径格式。
制作像这样的mac路径
tibble
到这样的POSIX路径
SSD:Users:UserName:Downloads:timesheet-export (40).csv
使用:
/Users/UserName/Downloads/timesheet-export (40).csv