Two MS Word macro syntax errors in Office 2013 under Win 8

I'm using MS Office Home and Student 2013 under a new computer running Win 8. I need help regarding two Word macro syntex errors - see the attached picture and the exact code below:


Can someone show how to correct the syntax, give some workaround or tell me what I need to do to obtain the same result in the macro?

=================================================================
            If WordNum > maxwords - 1 Then
                j = MsgBox("The maximum array size has been exceeded. _
                  Increase maxwords.", vbOKOnly)
                Exit For
            End If
        End If

        For l = j + 1 To WordNum
            If (Not ByFreq And Words(l) < Words(k)) Or
               (ByFreq And Freq(l) > Freq(k)) Then k = l
        Next l
  ==================================================================  
 
two-syntax-errors-in-red-3.jpg

  Thanks
LVL 18
WaterStreetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
        If WordNum > maxwords - 1 Then
                j = MsgBox("The maximum array size has been exceeded. " & _
                  "Increase maxwords.", vbOKOnly)
                Exit For
            End If
        End If

        For l = j + 1 To WordNum
            If (Not ByFreq And Words(l) < Words(k)) Or _
               (ByFreq And Freq(l) > Freq(k)) Then k = l
        Next l

Open in new window


I suggest that you avoid using 'Word' and 'Words' as variables in the Word Application. Word is a Range and Words is a collection of Word Ranges.
0
WaterStreetAuthor Commented:
I hope to try that later today.

Thanks.
0
WaterStreetAuthor Commented:
GrahamSkan

Didn't work.

I believe  made all the suggested changes, but I still get the Syntax error in the same two lines of code.  They show as red text in the edit window, so I made the in bold text below:

Here is the entire macro that I'm trying to use in MS Word under Office Home and Student 2013:

Sub WxxdFrequency()
    Dim SingleWxxd As String           'Raw Wxxd pulled from doc
    Const maxWxxds = 200000            'Maximum unique Wxxds allowed
    Dim Wxxds(maxWxxds) As String      'Array to hold unique Wxxds
    Dim Freq(maxWxxds) As Integer      'Frequency counter for unique Wxxds
    Dim WxxdNum As Integer             'Number of unique Wxxds
    Dim ByFreq As Boolean              'Flag for sorting order
    Dim ttlwxxds As Long                 'Total Wxxds in the document
    Dim Excludes As String             'Wxxds to be excluded
    Dim Found As Boolean               'Temporary flag
    Dim j As Integer                   'Temporary variables
    Dim k As Integer                   '
    Dim l As Integer                   '
    Dim Temp As Integer                '
    Dim tWxxd As String                '

    ' Set up excluded Wxxds
    Excludes = "[the][a][of][is][to][for][this][that][by][be][and][are]"

    ' Find out how to sort
    ByFreq = True
    ans = InputBox$("Sort by Wxxd or by FREQ?", "Sort order", "Wxxd")
    If ans = "" Then End
    If UCase(ans) = "Wxxd" Then
        ByFreq = False
    End If
   
    Selection.HomeKey Unit:=wxxdstory
    System.Cursor = wdCursorWait
    WxxdNum = 0
    ttlwxxds = ActiveDocument.Wxxds.Count

    ' Control the repeat
    For Each aWxxd In ActiveDocument.Wxxds

Open in new window

       SingleWxxd = Trim(LCase(aWxxd))
        If SingleWxxd < "a" Or SingleWxxd > "z" Then SingleWxxd = ""    'Out of range?
        If InStr(Excludes, "[" & SingleWxxd & "]") Then SingleWxxd = "" 'On exclude list?
        If Len(SingleWxxd) > 0 Then
            Found = False
            For j = 1 To WxxdNum
                If Wxxds(j) = SingleWxxd Then
                    Freq(j) = Freq(j) + 1
                    Found = True
                    Exit For
                End If
            Next j
            If Not Found Then
                WxxdNum = WxxdNum + 1
                Wxxds(WxxdNum) = SingleWxxd
                Freq(WxxdNum) = 1
            End If
            If WxxdNum > maxWxxds - 1 Then
                j = MsgBox("The maximum array size has been exceeded. _
                  Increase maxWxxds.", vbOKOnly)

                Exit For
            End If
        End If
        ttlwxxds = ttlwxxds - 1
        StatusBar = "Remaining: " & ttlwxxds & "     Unique: " & WxxdNum
    Next aWxxd

    ' Now sort it into word order
    For j = 1 To WxxdNum - 1
        k = j
        For l = j + 1 To WxxdNum
            If (Not ByFreq And Wxxds(l) < Wxxds(k)) Or
               (ByFreq And Freq(l) > Freq(k)) Then k = l

        Next l
        If k <> j Then
            wxxd = Wxxds(j)
            Wxxds(j) = Wxxds(k)
            Wxxds(k) = wxxd
            Temp = Freq(j)
            Freq(j) = Freq(k)
            Freq(k) = Temp
        End If
        StatusBar = "Sorting: " & WxxdNum - j
    Next j

    ' Now write out the results
    tmpName = ActiveDocument.AttachedTemplate.FullName
    Documents.Add Template:=tmpName, NewTemplate:=False
    Selection.ParagraphFormat.TabStops.ClearAll
    With Selection
        For j = 1 To WxxdNum
            .TypeText Text:=Trim(Str(Freq(j))) & vbTab & Wxxds(j) & vbCrLf
        Next j
    End With
    System.Cursor = wdCursorNormal
    j = MsgBox("There were " & Trim(Str(WxxdNum)) & _
        " different Wxxds ", vbOKOnly, "Finished")
End Sub
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

GrahamSkanRetiredCommented:
Just copy the code from from my comment and paste it in.

For the first error, you have used the line continuation character in the middle of a sting, which is not allowed in VB, so I have closed the string, added the concatenation operator (&) and the continuation character (_) and then opened another string on the next line.
For the second error, you have omitted the continuation character altogether.

In the new posting, you have also globally replaced Word with Wxxd, including places where you are actually referring to the range collection.

To save typing the default property of a range object is .Text, but it doesn't help us coders to understand the difference between a range and a string. You haven't declared it, but you aWxxd must be a range type.
Dim aWxxd  as Range
 For Each aWxxd In ActiveDocument.Words 
        SingleWxxd = Trim(LCase(aWxxd))
       ' The last line above above works, but
      'SingleWxxd = Trim(LCase(aWxxd.Text))
     'is a but clearer

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WaterStreetAuthor Commented:
Thanks Graham.
I hope to work with that later today.
0
WaterStreetAuthor Commented:
I got side tracked. I hope to try this later today.
0
WaterStreetAuthor Commented:
I didn't catch the syntax difference in the code you gave me in your first posting, until you explained it in your final posting; so, I awarded both equally, with the best answer being the explanation.

Thanks
0
WaterStreetAuthor Commented:
However, I then got a Run time error '4120'

Bad parameter in the following code line

 Selection.HomeKey Unit:=wxxdstory
 
 
But never mind. I'm awarding this question because you answered the one I originally asked, which cured the syntax errors that in the two pieces of code.

I abandoned this macro and have successfully used the one at
http://www.authorsden.com/categories/article_top.asp?catid=20&id=39307

It has an "excludes" feature which I have extended for my own use.


Thanks a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.