0

So what I'm trying to do is on an open word document using excel vba, I'm trying to go through each page of the word document and if the length of the range on any page is less than or equal to 20 (20 being the length of the subtitle that is bookmarked and then a page break is performed, leaving a blank page and 20 character spaces) then delete the page as it holds no content.

The following is what I have right now, but it doesnt work.

Dim Rng As Range, i as Long
For i = 1 To wdDoc.ComputeStatistics(wdStatisticPages)
    Set Rng = wdDoc.Goto(What:=wdGoToPage, Name:=i)
    Set Rng = Rng.Goto(What:=wdGoToBookmark, Name:="\page")
    If Len(Rng) <= 20 Then Rng.Delete
Next i
Jack Henderson
  • 93
  • 1
  • 12
  • you do not have any statement that compares anything to 20. did you post the wrong code? you have not stated what is failing. please describe the undesired behaviour that you are seeing. your statement is similar to _i want to drive to the market to buy some groceries. this is my car. but i cannot drive to the market_ – jsotola Jul 28 '17 at 19:25
  • I had been testing using 15 before, please see the revision. In terms of your response, I dont understand why it is failing which is why I posted it. From what I can see it isn't picking up the selection represented by Rng, causing a Run-Time error. @jsotola – Jack Henderson Jul 31 '17 at 13:17

0 Answers0