简体   繁体   中英

How to check in VBA that “no document is open”

I'm asking this question, because when the document is opened in safe mode, my macro crashes, pointing to this line:

strInput = ActiveDocument.Content

So, to prevent this error message:

This command is not available because no document is open. Error code 4248

I want to check whether there are opened documents or not. And if not, then to set some timer and loop until the user changes the mode of the document.

Do you mean the protected mode?

In that case you can handle the ProtectedViewWindowActivate event of the Application class which is fired when any protected view window is activated.

See Working with Document Protected View Events in Word for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM