2017-04-27 17 views
0

Mac(Excel 2015)でファイル選択ダイアログを開き、パスを返す機能があります。コードは以下の通りですが、パスは問題でコードではなく、Macで自分でデバッグする必要はありません。関数によって返されるパスは次のとおりです。Excel VBA - Macでファイルが見つかりません

SSD:ユーザー:ユーザー名:ダウンロード:.csvファイルのタイムシート輸出(40)

私が改正されました:ユーザー名:それは正しくショーのユーザーを行います。ファイルがこの場所に存在しない、私は私の道を送信するために、ユーザーを求め、彼らが送ら:

/ユーザー/ユーザー名/ダウンロード/タイムシートの輸出(40)は

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 
を.csvファイル

私はこれを実行すると、パス上に述べたように、私はエラー1004ファイルが見つかりませんを得るが、をピックアップし、FPの文字列で利用可能です:

Dim fp as string 

' if user on Mac etc... then 

fp = GetFileMac 

Set someWorkbook = Application.Workbooks.Open(fp) ' error here 

答えて

1

あなたはパス形式を変更する必要があります。

set myPath to POSIX path of myPath 
:この

/Users/UserName/Downloads/timesheet-export (40).csv 

使用のようなPOSIXパスにこの

SSD:Users:UserName:Downloads:timesheet-export (40).csv 

などのMACパスを作るために

関連する問題