Results 1 to 14 of 14
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CloseAll, save no changes (Word XP)

    I couldn't find a user-interface means of closing a set of documents without having to respond "N" sporadically.
    Such a situation arises when I've opened a slew of documents from Explorer, reviewed them, and want to be rid of them, but remain in Word.


    <pre>Public Sub CloseAllTakeNoPrisoners()
    Dim doc As Document
    For Each doc In Application.Documents
    doc.Close savechanges:=wdDoNotSaveChanges
    Next doc
    End Sub</pre>


  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    set the Saved property of each doc to True.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    When asked for the first time whether or not to save, holding the shift key whilst clicking on the No button will cause Word to accept that as "No to All".
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  4. #4
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: CloseAll, save no changes (Word XP)

    I assume this works in Excel too Pieterse! I have often wondered whats the use of choosing SHIFT+CloseAll and you still need to click on No or Save to confirm each induvidual document/sheet!

    If I hold down SHIFT and click No, it assumes No to All... Is this true if I hold SHIFT and click Save...Does it save all and close?
    Regards,
    Rudi

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    > set the Saved property of each doc to True.

    Thanks Howard, I'd neglected this, perhaps because in the past I'd had problems making it "stick" on Normal.dot, and had lost faith.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    > holding the shift key whilst clicking on the No button

    Jan Karel, you have again extended my knowledge. All these years I've explored the Shift key in conjunction with a menu, but never thought to use the Shift key with a dialogue box. Thanks.

    However (glum!) I'm unlikely to incorporate this as i am looking for a fast (1-click) method of removing all opened documents from my view. (apart from a call to Shutdown.exe!)

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    It works in Excel as well. That is where I discovered it.

    Dunno about the Save, probably.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  8. #8
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: CloseAll, save no changes (Word XP)

    Cheers Jan Karel....As Chris said, I learned something new by this that you mentioned> It will come in handy as I frequently delve into multiple files!
    Regards,
    Rudi

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    I've never seen .Saved failm unless there's a foolish 3rd party Auto* macro,
    I cauaught such a critter in OmniPagePro Office 14 last year, really stupid coding in OmniPage.

    I have seen DoNotSaveChanges fail, perhaps also due to 3rd party Auto macros, bur I've not investigated since .SAved is a more reliable approach anyway,

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    > there's a foolish 3rd party Auto* macro,

    Hmmm. I may be guilty. I do have those in effect, from time to time.
    My recollection centres mainly on trying to make changes to Normal.dot, and then avoiding the "Prompt To Save Normal template", by setting its .Saved to True. The failure appears to be sporadic, which is why I stopped trying to use it. Intermittent failure seemed worse than no implementation.

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    Ayup, that's what the AutoClose in OmniPage Pro Office 14 does.
    It modifies Normal.dot, NEEDLESSLY!!

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    What happens if you put this in Normal.Dot's Document:
    <pre>Private Sub Document_Close()
    thisdocument.Saved=True
    End Sub</pre>

    Does that catch it all before the Prompt To Save Normal.dot?

  13. #13
    Star Lounger
    Join Date
    Jan 2001
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    Why looping through the collection if the collection itself has a Close method?

    Documents.Close SaveChanges:=wdDoNotSaveChanges

  14. #14
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CloseAll, save no changes (Word XP)

    > Why looping through the collection if the collection itself has a Close method?

    Because I grew up with FORTAN II where everything was written as a loop?
    Because I didn't know it was there?
    because - I didn't used to know as much as you, but now I do (grin!).

    Thanks for this. A valuable lesson. Not just to skip one level of looping (generally leads to code that is much more readable!), but also for the long-term development that tells me "When you are considering looping through a collection, first check to see if the Method can be applied to the Collection itself"!

    Thanks again from me and, I'm sure, a few grizzled loungers who find THEMselves stroking their individual chins.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •