PublishObjects.Add不适用于MAC的Excel
我有一个代码,适用于Windows的Excel下工作正常,但不适用于Mac(2011)的Excel:
rng_str = "$A$1:$C$20" & (scrsheet_row_indx + 8) & """" rng_str = Left(rng_str, Len(rng_str) - 1) strFile = ThisWorkbook.Path & "\" & "Scorecard.htm" With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _ strFile, "scorecards", rng_str, _ xlHtmlStatic, "PublishToHtml", "") .Publish (True) End With
请让我知道,如果有人可以帮助我 – 如果你需要完整的代码,请让我知道。
提前致谢!
在Mac OS上运行macros时,在引用文件path时需要小心,因为不同的分隔符用于不同的操作系统。
在您的代码中,您已经在与ThisWorkbook.Path
和"Scorecard.htm"
连接中使用了\
,但是只有Windows使用\
作为分隔符。
不同的分隔符如下:
Windows: C:\myfolder\mydocument.txt
Unix: /usr/myuser/mydocument.txt
经典的Mac OS: Hard Drive:My Folder:My Document
这种方式将使用Application.PathSeparator
replace连接中的\
:
strFile = ThisWorkbook.Path & Application.PathSeparator & "Scorecard.htm"