vba 以编程方式保存 Excel 加载项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4505531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Programmatically Save Excel Add-In
提问by Tom
I have a worksheet updated occasionally by users that is used to make an Add-In (.XLAM). The Add-In is located on a network share and users link to it. I am looking to enable users to easily update this add-in (ensuring it is marked as read only)
我有一个由用户偶尔更新的工作表,用于制作加载项 (.XLAM)。加载项位于网络共享上,用户链接到它。我希望让用户能够轻松更新此加载项(确保将其标记为只读)
I have seen the article by Ken Puls hereon deploying Excel Add-Ins however the .SaveCopyAs
method he uses doesn't seem to be able to accept a file type.
我在此处看到Ken Puls撰写的关于部署 Excel 加载项的文章,但是.SaveCopyAs
他使用的方法似乎无法接受文件类型。
The .SaveAs
method does, however when this was tried I gota message saying the file format or extension was invalid, I have tried both with .XLAM and .XLA as below.
该.SaveAs
方法确实如此,但是在尝试此方法时,我收到一条消息,说文件格式或扩展名无效,我已尝试使用 .XLAM 和 .XLA,如下所示。
DeployPath = "C:\Menu.xlam"
.SaveAs Filename:=DeployPath, ReadOnlyRecommended:=True, FileFormat:=xlOpenXMLAddIn
Any help in this regard would be greatly appreciated.
在这方面的任何帮助将不胜感激。
回答by Charles Williams
I think that you need to use (Excel 2003 and earlier)
我认为您需要使用(Excel 2003 及更早版本)
ThisWorkbook.IsAddin = True
ThisWorkbook.SaveAs "fredyy", xlAddIn
For Excel 2007+ use
对于 Excel 2007+ 使用
ThisWorkbook.SaveAs "fredyy", xlOpenXMLAddIn
回答by Yishai
This is the solution that worked for me:
这是对我有用的解决方案:
Dim strRawName As String
strRawName = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".", -1, vbTextCompare) - 1))
ThisWorkbook.IsAddin = True
ThisWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & strRawName & ".xlam", FileFormat:=xlOpenXMLAddIn