Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To modify the parent window of a UserForm using VBA, the following steps can be followed:

  1. Declare a variable to represent the UserForm object:
Dim uf As UserForm
Set uf = UserForm1
  1. Set the ShowModal property of the UserForm object to False. This allows the UserForm to be treated as a regular window rather than a modal dialog box:
uf.ShowModal = False
  1. Use the hwnd property of the UserForm object to get the handle of the parent window:
Dim hwndParent As Long
hwndParent = uf.hwnd
  1. Use the SetParent API function to set the parent window of the UserForm to another window handle:
Dim hwndNewParent As Long
hwndNewParent = FindWindow("Notepad", vbNullString)
SetParent hwndParent, hwndNewParent

In this example, the parent window of the UserForm will be set to the Notepad window.