Vb.net Handles子句需要在包含类型或其基类型之一中定义的WithEvents变量?
当我在Visual Studio 2013中运行以下代码时,它显示:Vb.net Handles子句需要在包含类型或其基类型之一中定义的WithEvents变量?,vb.net,visual-studio-2013,Vb.net,Visual Studio 2013,当我在Visual Studio 2013中运行以下代码时,它显示: Handles子句需要在包含类型或其基本类型之一中定义的WithEvents变量 Private Sub Application_DocumentBeforeSave(ByVal Doc As Word.Document, ByRef SaveAsUI As Boolean, _ ByRef Cancel As Boolean) Handles Application.DocumentBeforeSave Do
Handles子句需要在包含类型或其基本类型之一中定义的WithEvents变量
Private Sub Application_DocumentBeforeSave(ByVal Doc As Word.Document, ByRef SaveAsUI As Boolean, _
ByRef Cancel As Boolean) Handles Application.DocumentBeforeSave
Doc.Paragraphs(1).Range.InsertParagraphBefore()
Doc.Paragraphs(1).Range.Text = "This text was added by using code."
End Sub
有人能告诉我如何解决这个问题吗?
上面的代码来自,该代码假定当前类有一个名为
Application
的字段,类型为Microsoft.Office.Interop.Word.Application
(其中包括DocumentBeforeSave
事件)
ThisAddin.vb
文件ThisAddin.Designer.vb
中定义的分部类,其中声明了应用程序
字段:该代码假定当前类有一个名为
Application
的字段,类型为Microsoft.Office.Interop.Word.Application
(其中包括DocumentBeforeSave
事件)
ThisAddin.vb
文件ThisAddin.Designer.vb
中定义的分部类,其中声明了应用程序
字段:Friend WithEvents Application As Microsoft.Office.Interop.Word.Application