Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2017, 01:19 PM
skarden skarden is offline How to dectect if close document and now no document open Windows Vista How to dectect if close document and now no document open Office 2010 64bit
Novice
How to dectect if close document and now no document open
 
Join Date: Dec 2011
Location: Orlando, FL
Posts: 26
skarden is on a distinguished road
Question How to dectect if close document and now no document open

I have buttons on the ribbon of my Word add-in template that I want to disable if there is no document open in Word. I know how to create an application level class and/or a document class. However, while the document class has a Close event, it fires before the document actually closes.

In the application class they have a BeforeClose, which, as expected, (also) fires before the document closes. They also have WindowActivate and WindowDeactivate events, but if I just close the only open document, so I now have a blank screen in Word, that doesn't fire either the WindowActivate or WindowDeactivate events.



I'm using the Application BeforeClose and testing If Documents.Count = 1 ... (as the document is about to close, so the Application Count should be going to zero) but that is a kludge.

Is there any event to test AfterClose (since, again, the Document class Close fires before the document actually closes.)?

Thanks,

Stuart
Reply With Quote
  #2  
Old 05-03-2017, 08:27 PM
gmayor's Avatar
gmayor gmayor is offline How to dectect if close document and now no document open Windows 10 How to dectect if close document and now no document open Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Are you overthinking this? Why not start the macro associated with the button with the lines

Code:
    If Documents.Count = 0 Then
        Beep
        Exit Sub
    End If
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 10-24-2022, 07:03 AM
skarden skarden is offline How to dectect if close document and now no document open Windows 10 How to dectect if close document and now no document open Office 2010 64bit
Novice
How to dectect if close document and now no document open
 
Join Date: Dec 2011
Location: Orlando, FL
Posts: 26
skarden is on a distinguished road
Default

I tried that and it didn't work as my getVisible ribbon callback, which runs when I invalidate myRibbon, happens before the document is actually closed, so Documents.Count still shows as 1.
Reply With Quote
Reply

Tags
after close, classes, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding tables to Created word document whilst other word document open Help rpb925 Word VBA 18 03-30-2016 04:45 PM
How to dectect if close document and now no document open Macro to Open to a Website When No Document Is Open lostinwebspace Word VBA 1 02-13-2016 10:28 AM
How to dectect if close document and now no document open Run-time error '1004': Document not saved. The document may be open... doctor_who12 Excel Programming 1 01-22-2014 04:47 PM
Prompt when close the document ubns Word 15 04-29-2012 10:07 PM
Can't Open My Document petra_lonely Word 0 03-09-2011 10:28 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:22 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft