移植到Mac时文件夹浏览器/选择器中断 [英] Folder browser/picker breaks when ported to Mac
问题描述
我一直在寻找答案,几乎所有人都含糊不清,所以我还是一无所知.我创建了一个程序,该程序打开2个文件,将它们同步,然后将文件保存到用户选择器的位置.在Windows上可以完美运行,这是我以为它可以在(愚蠢的假设...)上运行,但在Mac上却无法使用.我已经能够修复文件夹的打开,但是我需要修复保存部分.这是代码:
I've been searching for awhile for an answer to this, almost all were vague, so I'm still pretty clueless. I created a program that opens 2 files, synchronizes them, and then saves the file to a location the user chooser. Works perfect on Windows, which is what I assumed it would run on (stupid assumptions...), but is broken on Mac. I've been able to fix the opening of folders, but I need the saving section fixed. Heres the code:
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很了解,但是相对较快地掌握了一些东西.任何建议,将不胜感激!
I need to be able to control the NAME of the file with the program (subject's ID and session ID) but I need the FOLDER to save it to. I'm pretty knew to Mac, but pick up on things relatively quickly. Any advice would be appreciated!
推荐答案
供将来的搜索者使用:
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
Please note, after a few pages on Google, I finally stumbled upon this site: http://www.rondebruin.nl/mac/section3.htm
这篇关于移植到Mac时文件夹浏览器/选择器中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!