Ask Your Question
3

How can the parent window of a UserForm be modified using VBA?

asked 2022-08-28 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-01-28 15:00:00 +0000

woof gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-28 11:00:00 +0000

Seen: 9 times

Last updated: Jan 28 '22