title: Handles clause requires a WithEvents variable defined in the containing type or one of its base types?
body: <p>When I run the following code in Visual Studio 2013, it shows:</p>
  
  <p><code>Handles clause requires a WithEvents variable defined in the containing type or one of its base types</code></p>
  
  <pre><code>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
  </code></pre>
  
  <p>Can anyone tell me how to fix this problem?
  The code above is from <a href="https://msdn.microsoft.com/en-us/library/cc442946.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/cc442946.aspx</a></p>