Auto close open doc when opening another doc 
Author Message
 Auto close open doc when opening another doc

Hi all,

I am trying to close the active document when I'm opening
another one. To do this I have written an autoexec macro
in the second doc and the first thing it does is to call
ActiveDocument.close(false) but this just gives me an
invalid page fault.
What have I missed???

TIA
Andy



Sun, 26 Sep 2004 23:27:04 GMT  
 Auto close open doc when opening another doc
Hi Andy,

Quote:
> I am trying to close the active document when I'm opening
> another one. To do this I have written an autoexec macro
> in the second doc and the first thing it does is to call
> ActiveDocument.close(false) but this just gives me an
> invalid page fault.

If it calls ActiveDocument.Close then it will try to close
itself, I think.

The safer method might be to loop the Documents collection,
compare the name of each document to the name of the
document being opened (which is the activedocument) and
close any that do not match. Roughly:

Sub AutoOpen
    Dim doc as Word.Document

    For Each doc in Application.Documents
        If doc.Name <> ActiveDocument.Name then doc.close
    Next doc
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)



Mon, 27 Sep 2004 16:20:37 GMT  
 Auto close open doc when opening another doc

Quote:

>Sub AutoOpen
>    Dim doc as Word.Document

>    For Each doc in Application.Documents
>        If doc.Name <> ActiveDocument.Name then doc.close
>    Next doc
>End Sub

Thanks Cindy, simple and elegant!


Mon, 27 Sep 2004 18:40:28 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Open word 97 doc with doc name as variable

2. Open a doc, grab a range without having the whole doc being tabled

3. Opening a Word97 doc as a copy with no doc title

4. Auto run form when u open a word doc

5. Open second doc; close original

6. Close word doc open in webbrowser

7. Excel open .doc or word open .xls?

8. Auto Download of doc files into new doc file from a web site

9. Open Excel doc from VBA

10. Opening a Word Doc from Access with File Name Stored in a Table

11. What is the Best way to open a Word Doc

12. Opening Word Doc from runtime Access

 

 
Powered by phpBB® Forum Software