Merging duplicate pages in word

CaptainCsaba

Board Regular
Joined
Dec 8, 2017
Messages
78
Hi everyone!

First of all, this is a cross post and I am only posting it because although people were helpful on another forum I did not got a solution in the end and would like to ask your help too. You can find the original thread here and can post you answers there or I can add the solution later if this gets answered.

Original post:
http://www.vbaexpress.com/forum/showthread.php?62423-Merging-deleting-duplicate-pages

So the question is whether it is possible for word to find pages that are "duplicates" in a file and merge them. So for example if in a word file there are 20 pages that are the same, make it only 1 page. I already received a code from the forum admin "gmaxey" (if you are reading this, thank you, again) but I receive a weird error. You can find it at the end of the original post.

The question is. Does somebody know a way to either fix that error or to have a completely different solution to this problem?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Code:
Sub RemoveDuplicates()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 4/6/2018
Dim oPage As Page, oPagePrevious As Page
Dim oRngP As Range, oRngPP As Range
Dim lngIndex As Long
  For lngIndex = ActiveWindow.ActivePane.Pages.Count To 2 Step -1
    Set oPage = ActiveWindow.ActivePane.Pages(lngIndex)
    Set oPagePrevious = ActiveWindow.ActivePane.Pages(lngIndex - 1)
    Set oRngP = oPage.Rectangles(3).Range
    Set oRngPP = oPagePrevious.Rectangles(3).Range
    
    If Asc(oRngPP.Characters.Last.Previous) = 12 Then
      oRngPP.End = oRngPP.End - 2
    Else
      oRngPP.End = oRngPP.End - 1
    End If
    If Asc(oRngP.Characters.Last.Previous) = 12 Then
      oRngP.End = oRngP.End - 2
    Else
      oRngP.End = oRngP.End - 1
    End If
    If oRngP.Text = oRngPP.Text Then
      oPage.Rectangles(3).Range.Delete
    End If
  Next
lbl_Exit:
  Exit Sub
End Sub

So basically the code does find the pages it should delete but it only deletes the top paragraph ("row"). What could be the problem?
 
Upvote 0

Forum statistics

Threads
1,223,766
Messages
6,174,372
Members
452,560
Latest member
Turbos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top