Active Document behaviour 
Author Message
 Active Document behaviour

I have been testing having two documents open in Word
sharing the same template and accessing the same user
form.  I have named my documents test1 and test 2.  It
appears when I activate the user form from test2 and make
some changes and then close the form, the changes that I
programmed in the form are taking place in test1, as near
as I can tell.  Does this mean that Word doesn't
automatically return to the same document that was active
when entering the form?  If so, I will have more
questions, but I thought I would start off with this one
question first.  Perhaps I have something screwed up in my
programming. Thanks if you are able to help.


Wed, 04 Aug 2004 23:58:19 GMT  
 Active Document behaviour

Joanne,

I can't quite discern from your description what's happening, but it
sounds like what you're missing is an object variable(s) to refer to
your document(s).  ActiveDocument is OK when you know you have only
one document to play with, but in all other situations you need more
control, and your description illustrates why.

When you launch document test2, assign it an object variable:

   Dim doc2 as Document
   Set doc2 = Documents.Add

Then if your userform needs to do something to that document, say,
insert text at one of its bookmarks from a textbox on the userform,
use:

   doc2.Bookmarks("mybookmark").Range.InsertAfter TextBox1.Test

This way it doesn't matter which of your two documents is officially
active.


-- See the MVP FAQ at http://www.mvps.org/word --------------------------
----------------- "Life is nothing if you're not obsessed." --John Waters
-------------------------------------------------------------------------
Reply to group ONLY. Do not attach files. MVPs do not work for Microsoft.

Quote:

> I have been testing having two documents open in Word
> sharing the same template and accessing the same user
> form.  I have named my documents test1 and test 2.  It
> appears when I activate the user form from test2 and make
> some changes and then close the form, the changes that I
> programmed in the form are taking place in test1, as near
> as I can tell.  Does this mean that Word doesn't
> automatically return to the same document that was active
> when entering the form?  If so, I will have more
> questions, but I thought I would start off with this one
> question first.  Perhaps I have something screwed up in my
> programming. Thanks if you are able to help.



Thu, 05 Aug 2004 12:50:34 GMT  
 Active Document behaviour
Mark,

Thanks for the suggestion. Unfortunately, I will have no
control over how many documents a user decides to have
open at one time, whether it will be new documents or
loading exiting documents.

Do you know of a way to save the current document on going
into the user form and then making sure the active
document is set to that same document when it exits?  I
think it might have something to do with the "activate"
command, but I haven't been able to figure out how to use
that command properly.  As far as I can tell, it doesn't
want to return to the same document afterwards.  If you or
anyone is able to provide any guidance, I would be most
appreciative. Thanks.

Quote:
>-----Original Message-----

>Joanne,

>I can't quite discern from your description what's
happening, but it
>sounds like what you're missing is an object variable(s)
to refer to
>your document(s).  ActiveDocument is OK when you know you
have only
>one document to play with, but in all other situations
you need more
>control, and your description illustrates why.

>When you launch document test2, assign it an object
variable:

>   Dim doc2 as Document
>   Set doc2 = Documents.Add

>Then if your userform needs to do something to that
document, say,
>insert text at one of its bookmarks from a textbox on the
userform,
>use:

>   doc2.Bookmarks("mybookmark").Range.InsertAfter
TextBox1.Test

>This way it doesn't matter which of your two documents is
officially
>active.


MVP ------------
>-- See the MVP FAQ at http://www.mvps.org/word -----------
---------------
>----------------- "Life is nothing if you're not

obsessed." --John Waters

- Show quoted text -

Quote:
>----------------------------------------------------------
---------------
>Reply to group ONLY. Do not attach files. MVPs do not
work for Microsoft.


>> I have been testing having two documents open in Word
>> sharing the same template and accessing the same user
>> form.  I have named my documents test1 and test 2.  It
>> appears when I activate the user form from test2 and
make
>> some changes and then close the form, the changes that I
>> programmed in the form are taking place in test1, as
near
>> as I can tell.  Does this mean that Word doesn't
>> automatically return to the same document that was
active
>> when entering the form?  If so, I will have more
>> questions, but I thought I would start off with this one
>> question first.  Perhaps I have something screwed up in
my
>> programming. Thanks if you are able to help.
>.



Fri, 06 Aug 2004 10:18:46 GMT  
 Active Document behaviour

OK, this is just another side of the same issue, and the answer
is the same.  Assign an object variable to the active document
when you're sure it's the active one (in this case, that would
be before your userform loads):

   Set doc1 = ActiveDocument

Then, just before your userform unloads, use:

   doc1.Activate

To make sure it's active again.

Hope this helps.


-- See the MVP FAQ at http://www.mvps.org/word -------------
---- "Life is nothing if you're not obsessed." --John Waters
------------------------------------------------------------
Reply to the newsgroup *ONLY*.  MVPs are not Microsoft staff.

Quote:

> Mark,

> Thanks for the suggestion. Unfortunately, I will have no
> control over how many documents a user decides to have
> open at one time, whether it will be new documents or
> loading exiting documents.

> Do you know of a way to save the current document on going
> into the user form and then making sure the active
> document is set to that same document when it exits?  I
> think it might have something to do with the "activate"
> command, but I haven't been able to figure out how to use
> that command properly.  As far as I can tell, it doesn't
> want to return to the same document afterwards.  If you or
> anyone is able to provide any guidance, I would be most
> appreciative. Thanks.

> >-----Original Message-----

> >Joanne,

> >I can't quite discern from your description what's
> happening, but it
> >sounds like what you're missing is an object variable(s)
> to refer to
> >your document(s).  ActiveDocument is OK when you know you
> have only
> >one document to play with, but in all other situations
> you need more
> >control, and your description illustrates why.

> >When you launch document test2, assign it an object
> variable:

> >   Dim doc2 as Document
> >   Set doc2 = Documents.Add

> >Then if your userform needs to do something to that
> document, say,
> >insert text at one of its bookmarks from a textbox on the
> userform,
> >use:

> >   doc2.Bookmarks("mybookmark").Range.InsertAfter
> TextBox1.Test

> >This way it doesn't matter which of your two documents is
> officially
> >active.


> MVP ------------
> >-- See the MVP FAQ at http://www.mvps.org/word -----------
> ---------------
> >----------------- "Life is nothing if you're not
> obsessed." --John Waters
> >----------------------------------------------------------
> ---------------
> >Reply to group ONLY. Do not attach files. MVPs do not
> work for Microsoft.


> >> I have been testing having two documents open in Word
> >> sharing the same template and accessing the same user
> >> form.  I have named my documents test1 and test 2.  It
> >> appears when I activate the user form from test2 and
> make
> >> some changes and then close the form, the changes that I
> >> programmed in the form are taking place in test1, as
> near
> >> as I can tell.  Does this mean that Word doesn't
> >> automatically return to the same document that was
> active
> >> when entering the form?  If so, I will have more
> >> questions, but I thought I would start off with this one
> >> question first.  Perhaps I have something screwed up in
> my
> >> programming. Thanks if you are able to help.
> >.



Fri, 06 Aug 2004 13:44:31 GMT  
 Active Document behaviour
Thanks, Mark.  That is exactly what I was looking for.  I
didn't realize it was that simple.  I was thinking the
activate command, which I hadn't used before, needed an
object at the end and that I would have to go up one level
to the parent of the document.  Everything is working
perfectly now. Thanks again.

Quote:
>-----Original Message-----

>OK, this is just another side of the same issue, and the
answer
>is the same.  Assign an object variable to the active
document
>when you're sure it's the active one (in this case, that
would
>be before your userform loads):

>   Set doc1 = ActiveDocument

>Then, just before your userform unloads, use:

>   doc1.Activate

>To make sure it's active again.

>Hope this helps.


MVP
>-- See the MVP FAQ at http://www.mvps.org/word -----------
--
>---- "Life is nothing if you're not obsessed." --John
Waters
>----------------------------------------------------------
--
>Reply to the newsgroup *ONLY*.  MVPs are not Microsoft
staff.


>> Mark,

>> Thanks for the suggestion. Unfortunately, I will have no
>> control over how many documents a user decides to have
>> open at one time, whether it will be new documents or
>> loading exiting documents.

>> Do you know of a way to save the current document on
going
>> into the user form and then making sure the active
>> document is set to that same document when it exits?  I
>> think it might have something to do with the "activate"
>> command, but I haven't been able to figure out how to
use
>> that command properly.  As far as I can tell, it doesn't
>> want to return to the same document afterwards.  If you
or
>> anyone is able to provide any guidance, I would be most
>> appreciative. Thanks.

>> >-----Original Message-----

>> >Joanne,

>> >I can't quite discern from your description what's
>> happening, but it
>> >sounds like what you're missing is an object variable
(s)
>> to refer to
>> >your document(s).  ActiveDocument is OK when you know
you
>> have only
>> >one document to play with, but in all other situations
>> you need more
>> >control, and your description illustrates why.

>> >When you launch document test2, assign it an object
>> variable:

>> >   Dim doc2 as Document
>> >   Set doc2 = Documents.Add

>> >Then if your userform needs to do something to that
>> document, say,
>> >insert text at one of its bookmarks from a textbox on
the
>> userform,
>> >use:

>> >   doc2.Bookmarks("mybookmark").Range.InsertAfter
>> TextBox1.Test

>> >This way it doesn't matter which of your two documents
is
>> officially
>> >active.


Word
>> MVP ------------
>> >-- See the MVP FAQ at http://www.mvps.org/word --------
---
>> ---------------
>> >----------------- "Life is nothing if you're not
>> obsessed." --John Waters
>> >-------------------------------------------------------
---
>> ---------------
>> >Reply to group ONLY. Do not attach files. MVPs do not
>> work for Microsoft.


>> >> I have been testing having two documents open in Word
>> >> sharing the same template and accessing the same user
>> >> form.  I have named my documents test1 and test 2.  
It
>> >> appears when I activate the user form from test2 and
>> make
>> >> some changes and then close the form, the changes
that I
>> >> programmed in the form are taking place in test1, as
>> near
>> >> as I can tell.  Does this mean that Word doesn't
>> >> automatically return to the same document that was
>> active
>> >> { w?!  ?x |M-O??  when entering the form?  If

so, I will have more

- Show quoted text -

Quote:
>> >> questions, but I thought I would start off with this
one
>> >> question first.  Perhaps I have something screwed up
in
>> my
>> >> programming. Thanks if you are able to help.
>> >.

>.



Fri, 06 Aug 2004 22:40:30 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Macro to insert text or document into active document

2. Strange behaviour inside VBScript function (Active Server Page)

3. Activex Document - Strange behaviour

4. Adding a Document to the active contact

5. Save As with Active Document Name +1

6. OnLineView of active document

7. Maintaining Active Document Between Userforms

8. active documents

9. Counting the pages in an active document

10. check active document

11. rename active document

12. Protect Control in Active Document

 

 
Powered by phpBB® Forum Software