Share via

Word 2010 error using macro Selection.Sort: Run-time error '9125': String Passed can't be parsed

Anonymous
2013-08-19T04:36:51+00:00

Using Selection.Sort within a Word 2010 macro where FieldNumber is “Field 2” or greater, an error is generated.

The error generated is:

Run-time error '9125': String Passed can't be parsed

This line works fine:

Selection.Sort ExcludeHeader:=False, FieldNumber:="Field 1", SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, Separator:="=", SortColumn:=False, CaseSensitive:=False, LanguageID:=wdEnglishUS, SubFieldNumber:="Paragraphs"

But this line generates an error (only difference is "Field 1" was changed to "Field 2":

Selection.Sort ExcludeHeader:=False, FieldNumber:="Field 2", SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, Separator:="=", SortColumn:=False, CaseSensitive:=False, LanguageID:=wdEnglishUS, SubFieldNumber:="Paragraphs"

(http://support.microsoft.com/kb/231631) indicates it was a problem in WD2000, but I would expect this was addressed since “Paragraph” and “Field 1” works.

Curious if MS ever fixed this in future versions.

Thank you.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2013-08-19T06:07:11+00:00

Do you have an = separating the fields?

You will get an error if there is a mis-match between the field separator used and the Separator:= in the code.

Here if I use = as the field separator, sorting on Field 2 works with your code.  However, if I use

Separator:=vbTab and the fields are separated by =, a 9125 error occurs.  If is separate the fields with a tab space then the code using Separator:=vbTab works.

The reason why you can sort on Field 1 with a mismatch between the field separator that is use and that in the code is because the string does not then have to be parse to obtain the field on which to sort.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2013-08-19T13:28:27+00:00

    Thank you for taking the time to reply.

    I see where you are coming from, and I think I see the issue specific to my implementation. The key was your comment "However, if I use Separator:=vbTab and the fields are separated by =, a 9125 error occurs." What I found is:

    ·         When using the Selection.Sort method using the UI, if there are any rows which do not have a second field ("Field 2"), it will still sort it based on an empty field.

    ·         When using the Selection.Sort method using VB Scripting, if there are any rows which do not have a second field ("Field 2"), it will fail with the "Run-time error '9125'".

    Personally, I would think the behavior of the VB Script should be that of the UI, or put another way, the macro should behave the same as when it was recorded. In your test, if there was just one blank row, the command would likely fail if "Field 2" was specified.  In this case I would think this is a product bug given the behavior differences, but I am sure something like this would never see the light of day.

    Thanks again for your time.

    Was this answer helpful?

    0 comments No comments