excel - Excel 2016 for Mac 宏的运行时错误 1004(用于在 Excel 2011 for Mac 上工作)
问题描述
所以我试着环顾网络和论坛来解决这个问题,但由于我似乎根本无法理解这一点,我需要一些建议。
我有一个以前在 Mac 上的 Excel 2011 上运行的宏,但现在已经没有了。当我尝试在 Mac 上的 Excel 2016 上运行此程序时,我收到运行时错误“1004”,抱歉我们找不到(文件位置)。是否有可能它被移动,重命名等错误。
代码如下
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""} " & _
"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"
MyFiles = MacScript(MyScript)
On Error GoTo 0
If MyFiles <> "" Then
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
MySplit = Split(MyFiles, ",")
For N = LBound(MySplit) To UBound(MySplit)
X = ActiveWorkbook.Name
Workbooks.Open (MySplit(N))
当我看到调试时,它停在代码 Workbooks.Open (MySplit(N))
它正在寻找的文件存在于该位置,因为当它提示我时我必须选择该文件
想知道是否有人可以帮助我更换什么代码谢谢
解决方案
在Mac Excel 2016 VBA - Workbook.open 给出 1004 错误之后,只需修改 applescript 的输出以进行文件选择(类似于Macintosh HD:Users:xxxx:Documents:yyyy.xlsx
),通过替换:
为/
和Macintosh HD
使""
能Workbooks.Open()
工作。
推荐阅读
- google-sheets - 如何在不覆盖 Google 表格中的数据的情况下将数据行从 1 个选项卡复制到另一个选项卡
- python - 将嵌套列表转换为嵌套字典
- python - Python存储类列表并导出两者
- flutter - Flutter BottomNavigationBar 在 dispose 后更改页面索引或再次调用函数(带参数?)
- javascript - 获取从 ajax 调用动态添加的特定输入的值
- python - 如何从包含 CSV 数据的 ResultProxy 对象中检索 DataFrame?
- angular - 具有授权和角度的 CORS 配置
- python - 在带有 sklearn/Keras 的神经网络上使用 skopt 进行超参数优化
- linux - 用于测试文件是否存在于 bash 中的 shell 函数
- python - 从中提取一些东西