我为excel创建了一个插件,其中有一个功能区和一个按钮。我已使用以下代码处理了按钮单击事件
Private Sub test_button_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles test_button.Click
Dim activeWorksheet As Excel.Worksheet = Globals.ThisAddIn.Application.ActiveSheet
Dim str As String
Dim activeWorkbook As Excel.Workbook = Globals.ThisAddIn.Application.ActiveWorkbook
Dim sheet As Excel.Worksheet
Dim sheet_name As String
Globals.ThisAddIn.Application.Workbooks.Open("c:\\Test.xls")
str = Globals.ThisAddIn.Application.ActiveWorkbook.FullName
activeWorkbook.Save()
Globals.ThisAddIn.Application.Workbooks.Close()
'Call to python com object
Dim PythonUtils = CreateObject("PythonDemos.Utilities")
Dim response = PythonUtils.SplitString("Hello from VB", str)
MsgBox(response)
Globals.ThisAddIn.Application.Workbooks.Open("c:\\Test.xls")
End Sub
当调用返回时,应用程序打开工作簿,但是在打开它之后,它会进一步取消添加并调用ThisAddIn_Shutdown方法。任何人都可以帮我找出我出错的地方,如何停止卸载excel插件?
答案 0 :(得分:0)
我认为你的问题就在这里。
Globals.ThisAddIn.Application.Workbooks.Close()
在Excel中,Application.Workbooks.Close将关闭所有工作簿。这包括你的插件。您需要指定要关闭的工作簿。例如:
activeWorkbook.Close
或
Application.Workbooks("Test.xls").Close