title: Changing the parent workbook window of an add-in's userform
body: <p>I have been struggling with this question for quite some time now. </p>
  
  <p>I have a userform that is called from an Excel add-in I've built which then tests whether the current active workbook contains a specific structure. If not, it creates a new workbook with that exact structure. I set this workbook as well as another workbook that I open as wb1 and wb2.</p>
  
  <p>The issue is that the userform is initially called from the activeworkbook (could be any workbook) at the time of clicking the ribbon button and basically latches onto THAT workbook alone. </p>
  
  <p>Is there any way I could detach the userform from that workbook and change it to show my wb2 in the background of my userform?</p>
  
  <p>I have tried the following code, but it just closes my userform and doesn't work.</p>
  
  <pre><code> Option Explicit
  Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal clsName As String, ByVal wndName As String) As Long
  Private Declare PtrSafe Function SetParent Lib "user32" (ByVal hChild As Long, ByVal hParent As Long) As Long
  
  Private Sub CommandButton1_Click()
    Static h As Long
    If h &lt;= 0 Then h = FindWindow("ThunderDFrame", Me.Caption)
    If h &lt;= 0 Then Exit Sub
    Dim wb As Workbook: Set wb = Workbooks.Add
    SetParent h, Application.Windows(wb.Name).Hwnd
    wb.Activate
  End Sub
  </code></pre>
  
  <p>Any ideas?</p>