How best to identify that no chars appear in a given page? (In Word.)

Go To StackoverFlow.com

0

I'm faced with the prospect of blank pages scattered intermittently in a Word doc, which I'd like to discard. But I need to identify them in VBA first. There are spots in each where a caret lands if I click on the sheet.

But I don't know how to progress from there. How to instruct Word via VBA to identify whether the sheet has content in it?

2012-04-03 22:35
by M M


1

Something on these lines may suit.

ActiveDocument.Repaginate
j = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)

For i = j To 1 Step -1
    NotEmpty = True
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=CStr(i)
    Selection.GoTo What:=wdGoToBookmark, Name:="\page"
    If Selection.Characters.Count < 3 Then
        NotEmpty = False
        For Each c In Selection.Characters
            If Asc(c) > 13 Then
                ''Possibly not empty
                NotEmpty = True
            End If
        Next
    End If
    If NotEmpty = False Then
        Selection.Delete
    End If
Next
2012-04-03 23:30
by Fionnuala
That's quite incredible, Remou. You saved my project. Thanks - M M 2012-04-04 01:18
Ads