Word VBA: Opening a New Document

How do I get VBA to determine if the active document is completely blank?

I am opening Word from another program (in this case, Access) and I need to insure that the document that is active is completely blank.  If its not, I recognize that I have to open a new document with:

Word.Documents.Add DocumentType:=wdNewBlankDocument
Answer
Answer

Both of the following will return 1 for a document that has no text in the wdMainStory

MsgBox ActiveDocument.Characters.Count
MsgBox Len(ActiveDocument.Range)

That may be good enough for you, but the be really sure, you would have to check in all of the Word Story Ranges as, the above still return 1 for a document that has text in the header and footer.

To see how to access all of the Story Ranges, see the article "Using a macro to replace text where ever it appears in a document including Headers, Footers, Textboxes, etc.” at:

http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

 

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 468 Applies to: