I want to count the number of pages in Word documents using Excel VBA but some files can't be opened, with
"Error 5180 Word Cannot open document template".
Function PageWord(FullFile_Name As Variant, PF As Long)
Dim objWord As Object
Dim objDoc As Object
On Error Resume Next
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Set objDoc = objWord.Documents.Open(filename:="" & FullFile_Name & "", ReadOnly:=False)
objDoc.Repaginate
PageWord = objDoc.BuiltinDocumentProperties(14) 'Pages
Debug.Print PageWord & "-" & FullFile_Name
objWord.Quit (False)
End Function
How to open these files or is there another way to get the page counts?