title: Is Excel's Application.Hwnd property usable from 64 bit VBA?
body: <p>I need to obtain the Excel 2013 x64 window handle from 64 bit VBA code running in a spreadsheet. There are a couple of options to do this:</p>
  
  <ul>
  <li>Read <code>Application.Hwnd</code> (<a href="https://msdn.microsoft.com/en-us/library/office/ff840629(v=office.15).aspx" rel="nofollow noreferrer">MSDN Application.Hwnd Property (Excel)</a>)</li>
  <li>Call FindWindow, imported from user32, e.g. as described in the accepted answer here: <a href="https://stackoverflow.com/questions/3072356/what-are-the-differences-between-vba-6-0-and-vba-7-0">What are the differences between VBA 6.0 and VBA 7.0?</a>:</li>
  </ul>
  
  <pre>
      Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
             ByVal lpClassName As String, _
             ByVal lpWindowName As String) As LongPtr
  </pre>
  
  <p>The problem is that <code>Application.Hwnd</code> returns a <code>Long</code>, i.e. 32 bits (I've verified this with <code>MsgBox TypeName(Application.Hwnd)</code> within a 64 bit environment), whereas <code>FindWindow</code> returns a <code>LongPtr</code>, which is 64 bits long in Office x64.</p>
  
  <p>Does this mean that the <code>Application.Hwnd</code> property can't be trusted to always be correct in a 64 bit environment?</p>