Home > database >  How do I focus Word document after using userform in VBA?
How do I focus Word document after using userform in VBA?

Time:04-05

I have a small userform as interface to various VBA functions. I use these commonly for document automation like inserting tables formatted in certain way etc.

This works great, but I would like to have a workflow where I place the cursor at desired place, click the function, and can continue writing. Currently the form always keeps the focus after being clicked. The form is not modal.

So in image below, I have focus on (1) but want focus on (2) after VBA sub in form has completed.

image showing cut of VBA userform in front of inserted element (tooltip)

I did try ending the macro with ActiveDocument.ActiveWindow.SetFocus which does not make a difference.

I could of course close the form after every macro, but I use it commonly, so this would be less preferred.

CodePudding user response:

Please, try one of the two ways. Both of them have to work:

   Word.Application.Activate
   AppActivate ActiveDocument.ActiveWindow.Caption
  • Related