如何在vba for Mac中处理工作簿?

时间:2017-03-22 06:43:24

标签: excel vba macos excel-vba excel-vba-mac

我试图在PC上运行一个完美运行的宏,但是当我尝试在Mac上运行相同的宏时,我得到错误"1004";这表示无法找到该文件。 我这样写地址:

Workbooks.Open("\Macintosh HD\Usuarios\carlosstephan\Dropbox\SCEN Const.\GastosyPagosSCEN.xlsm")

有人知道怎么写得正确吗?。

我已尝试使用"/"代替"\",但它也无效。

使用此“with”弹出相同的错误:

With Sheets("Gastos")

    .Range(“A8”, .Cells(.Rows.Count, .Columns.Count)).Clear

End With

错误在哪里?。

3 个答案:

答案 0 :(得分:1)

除非Mac上的VBA与Windows不同,否则请更改

.Range(“A8”, .Cells(.Rows.Count, .Columns.Count)).Clear

.Range("A8", .Cells(.Rows.Count, .Columns.Count)).Clear

字符与"不同,不能用作字符串分隔符。

答案 1 :(得分:0)

这取决于您的Mac版本。我总是遇到让VBA在Mac上运行而Office 2016向后退一步的问题。

请参阅 http://www.rondebruin.nl/mac/mac017.htm

in 2011 it return a path like this :
Macintosh HD:Users:rdb:Desktop:YourFolder:
And in 2016  a path like this :
/Users/RDB/Desktop/YourFolder/
Reason is that in 2016 you must use the posix path in VBA codes

答案 2 :(得分:0)

使用以下VBA代码,您将知道哪个是您的分隔符:

Separator = Application.PathSeparator

或者如果您使用Inmediate窗口:

Debug.Print application.PathSeparator

知道分隔符后,将其替换为工作簿路径字符串,不要删除空格