我希望能进行一些健全性检查。我正在为 Mac 改编一个 Word 加载项(用 VBA 为 Word 2010 编写),具体来说,此时为 Word 2011。我知道其中的许多差异,但我无法找到其中的差异很多文档都明显缺乏 FileDialog。我最接近的答案在这里:http://www.rondebruin.nl/mac.htm http://www.rondebruin.nl/mac.htm作者使用Application.GetOpenFilename。不过,Word 似乎不存在这种方法(该网站的重点是 Excel)。
有谁知道如何使用 FileDialog 提供的文件和文件夹选择器对话框?我确实不熟悉 Applescript,但我必须学习一点才能解决 Word 2011 的时髦文件管理问题(Dir、FileCopy 等)。因此,如果这就是答案,那么对 Applescript 中的代码可能是什么样子的任何了解都将不胜感激。 (我或多或少知道如何将其翻译成VBA)。
我相信你必须使用 Apple Script 才能在 Mac 上做得更好。以下代码允许用户选择从函数以数组形式返回的文本文件。您只需修改 Apple 脚本即可返回其他文件类型并选择目录,我将把它留给您。
调用该函数并显示包含所有文件的消息框的代码:
Sub GetTextFilesOnMac()
Dim vFileName As Variant
'Call the function to return the files
vFileName = Select_File_Or_Files_Mac
'If it's empty then the user cancelled
If IsEmpty(vFileName) Then Exit Sub
'Loop through all the files specified
For ii = LBound(vFileName) To UBound(vFileName)
MsgBox vFileName(ii)
Next ii
End Sub
Apple 脚本运行的函数是:
Function Select_File_Or_Files_Mac() As Variant
'Uses AppleScript to select files on a Mac
Dim MyPath As String, MyScript As String, MyFiles As String, MySplit As Variant
'Get the documents folder as a default
On Error Resume Next
MyPath = MacScript("return (path to documents folder) as String")
'Set up the Apple Script to look for text files
MyScript = "set applescript's text item delimiters to "","" " & vbNewLine & _
"set theFiles to (choose file of type " & " {""public.TEXT""} " & _
"with prompt ""Please select a file or files"" default location alias """ & _
MyPath & """ multiple selections allowed true) as string" & vbNewLine & _
"set applescript's text item delimiters to """" " & vbNewLine & _
"return theFiles"
'Run the Apple Script
MyFiles = MacScript(MyScript)
On Error GoTo 0
'If there are multiple files, split it into an array and return the results
If MyFiles <> "" Then
MySplit = Split(MyFiles, ",")
Select_File_Or_Files_Mac = MySplit
End If
End Function
最后,指定不同的文件类型可能有点麻烦,如果您只想指定Word文档,则替换public.TEXT
with com.microsoft.word.doc
,但是这不允许.docx
or .docm
文件。你需要使用org.openxmlformats.wordprocessingml.document
and org.openxmlformats.wordprocessingml.document.macroenabled
分别针对这些。有关这些的更多信息,请参阅:https://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/understand_utis/understand_utis_conc/understand_utis_conc.html https://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)