Link to home
Start Free TrialLog in
Avatar of Aj Pdl
Aj Pdl

asked on

How to check word document file is empty or not from excel macro?

I want to check user provided MS word file is empty or not from excel macro.
Although i test as following example, its not work.
 Word VBA: How do I determine if the current Word document is ...
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

You can check the characters count of the document like this to see if the document is empty...

Dim doc As Document
Set doc = ActiveDocument
If doc.Range.Characters.Count = 1 Then
    MsgBox "The document is empty.", vbInformation
End If

Open in new window

Avatar of Aj Pdl
Aj Pdl

ASKER

Thanks for your answer Mr. Neeeraj.

But, its work only if document include text and picture, not working document only include shape object (eg. following image).
User generated image
Thanks for helping me.
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Test the file size:

Function IsFileEmpty (strFileName As String) As Boolean
    IsFileEmpty = FileLen(strFileName) = 0
End Function

Open in new window

Avatar of Aj Pdl

ASKER

Thanks for everyone, Thanks @Rgonzo1971. Its work now. :)
Just out of curiosity, did you try my proposed solution?
That's my fault. I should have asked you about the criteria for considering a document empty. Never mind, glad your issue has been resolved. :)