VB.net Office VSTO Addin WorkbookBeforeSave 没有签名兼容
我尝试从 Office 的 VSTO Addin 开始,并翻译了 Microsoft 在其 网站 。但是,当我实现 WorkbookBeforeSave
事件时,我总是收到此错误:
方法 'Application_WorkbookBeforeSave' 无法处理事件 'WorkbookBeforeSave' 因为它们没有兼容的签名
我在 google 中搜索并看起来签名没问题。我在 C# 中尝试了这个示例,效果很好。
这是我的代码:
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.Excel
Public Class ThisAddIn
Private Sub ThisAddIn_Startup() Handles Me.Startup
AddHandler Application.WorkbookBeforeSave, New Excel.AppEvents_WorkbookBeforeSaveEventHandler(AddressOf Application_WorkbookBeforeSave)
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
Sub Application_WorkbookBeforeSave(wb As Workbook, SaveUI As Boolean, Cancel As Boolean) Handles Application.WorkbookBeforeSave(
Dim activeworksheet As Worksheet = Application.ActiveSheet
Dim firstRow As Range = activeworksheet.get_range("A1")
firstRow.EntireRow.Insert(Excel.XlInsertShiftDirection.xlShiftDown)
Dim newFirstRow As Range = activeworksheet.get_tange("A1")
newFirstRow.Value2 = "This text was added by using code"
End Sub
End Class
错误是包含“(AddressOf Application_WorkbookBeforeSave)”的行 有人可以帮我解决这个问题吗? 谢谢
I was trying to start with VSTO Addin for Office and I translated an example Microsoft published in their site . But I always receive this error when I implemented the WorkbookBeforeSave
event:
Method 'Application_WorkbookBeforeSave' cannot handle event 'WorkbookBeforeSave' because they do not have a compatible signature
I searched in google and it looks the signature is ok. I tried this examples in C# and it worked fine.
this is the code I have:
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.Excel
Public Class ThisAddIn
Private Sub ThisAddIn_Startup() Handles Me.Startup
AddHandler Application.WorkbookBeforeSave, New Excel.AppEvents_WorkbookBeforeSaveEventHandler(AddressOf Application_WorkbookBeforeSave)
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
Sub Application_WorkbookBeforeSave(wb As Workbook, SaveUI As Boolean, Cancel As Boolean) Handles Application.WorkbookBeforeSave(
Dim activeworksheet As Worksheet = Application.ActiveSheet
Dim firstRow As Range = activeworksheet.get_range("A1")
firstRow.EntireRow.Insert(Excel.XlInsertShiftDirection.xlShiftDown)
Dim newFirstRow As Range = activeworksheet.get_tange("A1")
newFirstRow.Value2 = "This text was added by using code"
End Sub
End Class
The error is the line that has "(AddressOf Application_WorkbookBeforeSave)"
Could somebody help me with this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题,这是我的错误。错误出现在声明中:
参数
Cancel as Boolean
应该是By Ref Cancel as Boolean
I found the problem, it was my mistake. The mistake was in the declaration :
The argument
Cancel as Boolean
should beBy Ref Cancel as Boolean