title: Excel 2010 VBA Macro to close specific notepad window. (findwindow gives mismatch type error??)
body: <p>So I'm experimenting with closing windows/apps in a vba macro I'm writing. Numerous posts online suggest the use of <code>FindWindow</code> from the windows api.</p>
  
  <p>I'm starting out slow, I'm trying to close a notepad window from my macro. (its one of a few things I want but it seems the easiest) and I found a solution, I forget where it was posted, it was short and sweet. </p>
  
  <pre><code>Sub CheckNotepad()
  Dim hwnd As Long
  hwnd = FindWindow("Notepad", vbNullString)
  If hwnd Then
      MsgBox "Notepad is running, the window handle is " &amp; hwnd
  Else
      MsgBox "Notepad is not running"
  End If
  End Sub
  </code></pre>
  
  <p>seems great, its the start of how to get the handle for the notepad window, and from there I could find code to close the window using that handle. But it doesn't work for me!</p>
  
  <p>All of the examples I have found use the 2 arguments, I would say half of which use <code>vbNullString</code> as the second, some of which use a string for the caption of a particular window. But none of it works for me. </p>
  
  <p>The only thing that works is supplying a 0 for the second argument (I assume this is in place of <code>vbNullString</code>) but if I try to use <code>vbnullstring</code>, or an actual string, I get a type mismatch error. and if I try to use any other number then excel stops working. (the lovely "Program has stopped working" message appears.</p>
  
  <p>So, can give me some advise as to why this happens? I could just use the 0, but I'm guessing my user will have other notepad windows open so I'd like to be able to supply an argument to find the specific notepad window. (its going to be a temp window, popped up during the macro and subsequently closed as I do not want it left open for them to see)</p>
  
  <p>Thanks in advance </p>