当移植到Mac时,文件夹浏览器/选取器会中断

我一直在寻找答案,几乎都是模糊的,所以我还是很笨。 我创build了一个程序,打开2个文件,同步它们,然后将文件保存到用户select器的位置。 在Windows上完美工作,这是我认为它会运行(愚蠢的假设…),但在Mac上被打破。 我已经能够修复打开文件夹,但我需要修复保存部分。 这里是代码:

Function GetFolder(strPath As String) As String Dim sItem As String Dim sFile As String Dim fldr As FileDialog Set fldr = Application.FileDialog(msoFileDialogFolderPicker) With fldr .Title = "Select a Folder" .AllowMultiSelect = False .InitialFileName = strPath If .Show <> -1 Then GoTo NextCode sItem = .SelectedItems(1) End With NextCode: GetFolder = sItem Set fldr = Nothing sFile = "\" & sSubID & "-" & sSubSession & "-synced.txt" ActiveWorkbook.SaveAs Filename:=sItem & sFile, FileFormat:=xlTextWindows, CreateBackup:=False End Function 

我需要能够用程序(主体的ID和会话ID)来控制文件的名称,但我需要FOLDER来保存它。 我对Mac非常了解,但要相对迅速地select一些东西。 任何意见,将不胜感激!

对于未来的search者:

 Function GetFolder(strPath As String) As String Dim sFile As String Dim folderPath As String Dim RootFolder As String sFile = sSubID & "-" & sSubSession & "-synced.txt" On Error Resume Next RootFolder = MacScript("return (path to desktop folder) as String") folderPath = MacScript("(choose folder with prompt ""Select the folder""" & _ "default location alias """ & RootFolder & """) as string") On Error GoTo 0 If folderPath <> "" Then ActiveWorkbook.SaveAs Filename:=folderPath & sFile, FileFormat:=xlTextWindows, CreateBackup:=False End If 

请注意,在Google上几页之后,我终于偶然发现了这个网站: http : //www.rondebruin.nl/mac/section3.htm

我想我发现你的问题:

 sFile = "\" & sSubID & "-" & sSubSession & "-synced.txt" 

反斜杠\特定于Windowspath。 对于基于UNIX的操作系统,您必须使用/

在互联网上发现的一些提示有一个跨平台的path:

 Application.PathSeparator 

对于你的路线,这将是:

 sFile = Application.PathSeparator & sSubID & "-" & sSubSession & "-synced.txt"