0

我一直在寻找这个问题的答案,几乎所有的都是模糊的,所以我仍然很无能。我创建了一个程序,它打开 2 个文件,同步它们,然后将文件保存到用户选择器的位置。在 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),但我需要将其保存到文件夹。我对 Mac 非常了解,但相对较快地掌握了一些东西。任何意见,将不胜感激!

4

2 回答 2

2

对于未来的搜索者:

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

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

于 2013-05-14T18:14:47.743 回答
0

我想我发现了你的问题:

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

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

在 Internet 上找到的一些提示具有跨平台路径:

Application.PathSeparator

对于您的线路,它将是:

sFile = Application.PathSeparator & sSubID & "-" & sSubSession & "-synced.txt"
于 2013-05-14T17:56:13.067 回答