15-02-22 10:04 AM
Hello Everyone!
I have executed the below code for its purpose "To delete blank pages" and it works correctly.
The problem is that in some pages which are Blank it do not delete them.
Now ,the point is that these Blank pages looks like ""blank" but in fact they have spaces on it,and that is the reason that the below code do not delete them.
Please,If someone could help me to add a condition into the code to check first for that blank charachters or that blank spaces that are in some pages.Delete them ,and then delete the blank pages.
Thank you ,
Erjola
Dim d = GetDocument(handle,documentname)Dim a As Object = GetInstance(handle)Dim oDoc = dDim para As ObjectDim i As Integer=1Dim oRng As ObjectDim lParas As LongDim lEnd As LongDim lDeleted As LongDim wdGoToPage As IntegerDim wdGoToAbsolute As IntegerConst wdCharacter As Integer = 1lParas = oDoc.Paragraphs.CountDo While i = i + 1oDoc.Selection.GoTo (What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=i)oRng = a.Selection.RangeoRng.End = a.Selection.Bookmarks("\Page").Range.EndoRng.SelectlEnd = lEnd + oRng.Paragraphs.Count ' Keep track of how many processedFor Each para In oRng.ParagraphsIf Len(para.Range.Text) = 1 Thenpara.Range.DeletelDeleted = lDeleted + 1Else ' If not blank, then delete o more in this page!Exit ForEnd IfNext para' Calc how many paragraphs processedIf lDeleted + lEnd >= lParas Then ' If more that we started with, let's call it a day!Exit DoEnd IfLooplParas = oDoc.Paragraphs.Count ' Total paragraph countlDeleted = 0 ' reset stuff - in caselEnd = 0i = 0Doi = i + 1a.Selection.GoTo (What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=i)oRng = a.Selection.RangeoRng.End = a.Selection.Bookmarks("\Page").Range.EndoRng.SelectlEnd = lEnd + oRng.Paragraphs.CountIf oRng.Paragraphs.Count = 1 ThenIf oRng.Paragraphs(1).Range.Text = Chr(12) & Chr(13) ThenoRng.Paragraphs(1).Range.DeletelDeleted = lDeleted + 1i = i - 1'ElseIf Len(oRng.Paragraphs(1).Range.Text) = 1 Then' oRng.Paragraphs(1).Range.Delete' lDeleted = lDeleted + 1' i = i - 1End IfEnd IfIf lEnd >= lParas ThenExit DoEnd IfLoop' Finally!!! Deal with the lingering final page-break!a.Selection.GoTo (What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=999 ) ' Go to Last Page.oRng = a.Selection.Range ' Select the end..oRng.MoveStart (wdCharacter, -3 ) ' Backup 3 charactersIf Left(oRng.Text, 2) = Chr(13) & Chr(12) Then ' Should be 13+12oRng.Text = "" ' Remove that thingy!End Ifpara = NothingoDoc = Nothing
Answered! Go to Answer.
15-02-22 11:25 AM
15-02-22 11:25 AM