Consulting

Results 1 to 6 of 6

Thread: Is it possible to find duplicate paragraphs or sentences in MAC word

  1. #1
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    3
    Location

    Is it possible to find duplicate paragraphs or sentences in MAC word

    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

    Last edited by macropod; 01-13-2020 at 02:59 PM. Reason: Added code tags & formatting

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    3
    Location

    Thanks macropod

    Quote Originally Posted by macropod View Post
    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

  4. #4
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    3
    Location
    Hi all

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

    Thank you

    Regards

    Leo


  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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) & """"
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •