PDA

View Full Version : [SOLVED:] Is it possible to find duplicate paragraphs or sentences in MAC word



Leo2020
01-13-2020, 07:02 AM
Hi all
Thank you so much in advance for your precious help and advice
I am at the final stage of finishing my PhD, about 500pages, it took more than 6 years, I am sure I have repead sentences over the last years throughout the document, it is 500pages word document.
I have tried out several proposed codes using VBA, but unfortunately, I keep receiving syntax error when I run the code
I am not sure what´s the problem, is the version of the word?, the code?
I am using Mac pro, mac os high sierra 10.13.6
Microsoft word for mac 201, version 14.5.1
This is the code that I copy and paste at VBA
Thank you again for your kind help and time


Option Explicit
Sub Sample()
Dim MyArray() As String
Dim n As Long, i As Long
Dim Col As New Collection
Dim itm
n = 0
'~~> Get all the sentences from the word document in an array
For i = 1 To ActiveDocument.Sentences.Count
n = n + 1
ReDim Preserve MyArray(n)
MyArray(n) = Trim(ActiveDocument.Sentences(i).Text)
Next
'~~> Sort the array
SortArray MyArray, 0, UBound(MyArray)
'~~> Extract Duplicates
For i = 1 To UBound(MyArray)
If i = UBound(MyArray) Then Exit For
If InStr(1, MyArray(i + 1), MyArray(i), vbTextCompare) Then
On Error Resume Next
Col.Add MyArray(i), """" & MyArray(i) & """"
On Error GoTo 0
End If
Next i
'~~> Highlight duplicates
For Each itm In Col
Selection.Find.ClearFormatting
Selection.HomeKey wdStory, wdMove
Selection.Find.Execute itm
Do Until Selection.Find.Found = False
Selection.Range.HighlightColorIndex = wdPink
Selection.Find.Execute
Loop
Next
End Sub
'~~> Sort the array
Public Sub SortArray(vArray As Variant, i As Long, j As Long)
Dim tmp As Variant, tmpSwap As Variant
Dim ii As Long, jj As Long
ii = i: jj = j: tmp = vArray((i + j) \ 2)
While (ii <= jj)
While (vArray(ii) < tmp And ii < j)
ii = ii + 1
Wend
While (tmp < vArray(jj) And jj > i)
jj = jj - 1
Wend
If (ii <= jj) Then
tmpSwap = vArray(ii)
vArray(ii) = vArray(jj): vArray(jj) = tmpSwap
ii = ii + 1: jj = jj - 1
End If
Wend
If (i < jj) Then SortArray vArray, i, jj
If (ii < j) Then SortArray vArray, ii, j
End Sub

macropod
01-13-2020, 03:02 PM
Your posted code contains a lot of what appears to be html coding, not just VBA. Please correct it.

Also, when posting code, please format your code correctly and enclose it in CODE tages to preserve the formatting - see the edits I've made to your post.

Leo2020
01-14-2020, 03:13 AM
Your posted code contains a lot of what appears to be html coding, not just VBA. Please correct it.

Also, when posting code, please format your code correctly and enclose it in CODE tages to preserve the formatting - see the edits I've made to your post.



Very sorry macropod, as I have mentioned I am ignorant about both VBA and html coding, I found the code in a website, it supposed to be for duplicated sentences for mac microsoft word

Could you kindly you or anyone from this community provide me with any code for duplicate paragraphs or sentences for MAC microsoft word 2011

Macropod you are very knowledgeable with this, I hope you code help

Thank you
Kind regards

Leo2020
01-15-2020, 08:18 AM
Hi all

Any help with the above please?
Is it possible to find duplicate paragraphs or sentences in MAC wordThank you

Regards

Leo

SamT
01-15-2020, 11:49 AM
I am ignorant about ... html coding,
html code words for characters start with an Ampersand and end with a semicolon. Ex > represents the character >

Col.Add MyArray(i), """" & MyArray(i) & """"

Col.Add MyArray(i), """" & MyArray(i) & """"

macropod
01-15-2020, 03:14 PM
See: https://www.msofficeforums.com/word-vba/33610-how-find-duplicate-phrases-paragraphs-long-document.html