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

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.

Answer
Answer

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.

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 420 Applies to: