|
-
Dec 15th, 2010, 02:42 PM
#1
Thread Starter
New Member
Word-When macro shows a hidden form, visible Word document changes
The elements
I have a UserForm: Userform1.
Userform1 only has a command button: cmdHide.
The only code in cmdHide is:
Me.Hide
I have a VBA macro: Macro1.
The only code in the macro is:
Userform1.show
I have two Word documents open: Doc1 and Doc2.
Doc1 is at the front (that is, it’s the visible document on the screen).
The action
Now, I do the following:
I run Macro1. The macro loads and shows Userform1.
I click on cmdHide. The macro hides Userform1 and leaves.
Now I bring Doc2 to the front.
I run Macro1 again. The macro BRINGS Doc1 TO THE FRONT, and then shows the hidden Userform1.
The problem
My problem is, I don’t want Doc1 brought to the front, I want Doc2 to stay at the front.
Comments and additional information
-It seems that, when a macro has to show a form that has been hidden, it first looks through the collection of open documents. If the document that was at the front when the form was loaded is in the collection, then it brings that document to the front; if it’s not, then it leaves the document that is already there. In this case, it finds Doc1, so it brings it to the front. If I had closed Doc1 BEFORE running Macro1 for the second time, then the macro would have left Doc2 at the front and would have shown the hidden form.
-When I say “show the hidden form”, I mean I am sure it is showing the hidden form, and not loading it again.
-In this example, I only referred to two documents, but this behavior occurs no matter how many documents are open.
-At all times through this process, the “ActiveDocument” object retains its correct values. Even after “The macro BRINGS Doc1 TO THE FRONT”, as I said further up, ActiveDocument points to Doc2.
Does anybody out there know why this happens, and how I can solve it?
Thank you very much!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|