Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sorting in Word by Macro

4 views
Skip to first unread message

splash

unread,
Jan 18, 2002, 1:12:03 PM1/18/02
to
So, in Word, I created a macro to sort everything by Word2, then Word1.
Great. Then, when I try to run the macro again, I get the following error:
"Run-time Error '9125': String passed can't be parsed". What the heck does
that mean? Help doesn't. (FYI: I'm asking VBA group since I also intend
to add VBA code to the sub after the sort.)

Sub Macro1()
' Dim oSheet As Document
' Set oSheet = Application.ActiveDocument
Selection.WholeStory
Selection.Sort ExcludeHeader:=False, FieldNumber:="Word 2",
SortFieldType _
:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending,
FieldNumber2 _
:="Word 1", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending,
Separator:= _
wdSortSeparateByDefaultTableSeparator, SortColumn:=False,
CaseSensitive:= _
False, LanguageID:=wdEnglishUS
End Sub


Balkrishna Isvaran

unread,
Jan 19, 2002, 2:10:58 AM1/19/02
to
do you have lines which have only one word or no words? could processing
such lines give the error?

splash <spl...@mosquitonet.com> wrote in message
news:u4gpbko...@corp.supernews.com...


> So, in Word, I created a macro to sort everything by Word2, then Word1.
> Great. Then, when I try to run the macro again, I get the following
error:
> "Run-time Error '9125': String passed can't be parsed". What the heck
does
> that mean? Help doesn't.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.314 / Virus Database: 175 - Release Date: 11/01/02


Dave Rado

unread,
Jan 19, 2002, 6:22:48 AM1/19/02
to
Hi Balkrishna and "Splash"

I get the reported error when I run that macro *regardless* of what's in the
document.

My understanding is that Word *can't* sort paragraphs by word number. And
I'm not sure where: FieldNumber:="Word 2" came from. If I record a macro
while sorting paragraphs, I get: FieldNumber:="Paragraphs" in the recorded
code. If I sort a table, I get: FieldNumber:="Column x" (x being the column
number I chose to sort on).

OTOH, you could use a wildcard F&R to change the word order, do the sort and
then use a wildcard F&R to change the word order back to how it was ..

Regards

Dave


"Balkrishna Isvaran" <isv...@vsnl.com> wrote in message
news:#aE#YhLoBHA.1644@tkmsftngp05...

Klaus Linke

unread,
Jan 19, 2002, 7:30:24 AM1/19/02
to
Dave Rado <dr...@onetel.net.uk> wote:

> My understanding is that Word *can't* sort paragraphs by word
number.
> And I'm not sure where: FieldNumber:="Word 2" came from.

Hi Dave,

Go into Table > Sort > Options, choose "Field delimiter = Other:
Blank", then look if you still can't see Field Number:="Word 2".

I think Balkrishna has nailed down the most probable reason for the
error message.

Greetings, Klaus


Dave Rado

unread,
Jan 19, 2002, 7:42:19 AM1/19/02
to
Hi Klaus

When I go to Table + Sort + Options, (W2k), if I set "Separate fields as" to
"Other", it won't let me leave the box blank (if I do anbd click OK, I get
an error message: "You must type a character"). If I type a space in the
"Other" box, it does indeed sort by the second word - so I've learnt
something new today - thanks! <g> - but the recorded code I get (which also
sorts by the secnd word when I run it) is:

Selection.Sort ExcludeHeader:=False, FieldNumber:="Paragraphs", _
SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderDescending, _
FieldNumber2:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _


wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
wdSortSeparateByDefaultTableSeparator, SortColumn:=False, CaseSensitive:= _

False, LanguageID:=wdEnglishUK

What am I doing wrong?

Regards

Dave


"Klaus Linke" <fotosatz...@t-online.de> wrote in message
news:a2bngi$pun$03$1...@news.t-online.com...

Klaus Linke

unread,
Jan 19, 2002, 8:49:56 AM1/19/02
to
Hi Dave,

As you have guessed, I meant a "space", not "blank".

Other field delimiters like "/" or "." work just as well (may be handy
to sort dates or other formatted data; though I have rarely used it).

This feature came up some weeks ago in the docmanagement-ng:
http://groups.google.com/groups?threadm=9vm351%24v6b%2406%241%40news.t
-online.com

When I try it, the macro recorder records fine (FieldNumber:="Wort 3"
if I sort on the third word).

Greetings, Klaus


Dave Rado

unread,
Jan 19, 2002, 9:02:43 AM1/19/02
to
Well knock me down with a feather!!!

FWIW, the step I was missing was that after *closing* the Options box you
*then* change the "Sort by" in the "Sort text" dialog. I misunderstoof your
previous post, and was expecting the Options dialog itself to change.

Now that *is* neat! *Provided* you use Word 2000+. Unfortunately, in Word
97, I can't get the "Sort by" list to display anything other than
"Paragraphs" and
"Word 1", no matter what I do.

Is this a Word 97 bug or am I doing something wrong (I *did* try Cindy's
suggestion of going back to Options a second time but that
fifn't work for me). Doing it programmatically *does* work for me, even in
Word 97; so the following *does* sort by "Word 2", even
in 97

Selection.Sort ExcludeHeader:=False, FieldNumber:="Word 2", SortFieldType _
:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, FieldNumber2
_

:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
wdSortSeparateByDefaultTableSeparator, SortColumn:=False,
CaseSensitive:= _

False, LanguageID:=wdLanguageNone

Regards

Dave

"Klaus Linke" <fotosatz...@t-online.de> wrote in message

news:a2bs5k$eua$06$1...@news.t-online.com...

Klaus Linke

unread,
Jan 19, 2002, 10:05:38 AM1/19/02
to
Hi Dave,

I see you use Separator:= wdSortSeparateByDefaultTableSeparator in
your code.
I think you can use Separator:=" " (or any other character)
explicitly, but I haven't found that in the online-help anywhere.

Greetings, Klaus

"Dave Rado" <dr...@onetel.net.uk> schrieb im Newsbeitrag
news:eXtegJPoBHA.980@tkmsftngp03...

Jay Freedman

unread,
Jan 19, 2002, 5:55:03 PM1/19/02
to
According to the help, the Separator is a Variant that "can be one of
the WdSortSeparator constants" -- the implication is that it can be
any character, and that does indeed work.

I experimented a bit, and I found the kind of bizarre results that
I've come to expect of Word VBA <g>.

The 9125 error occurs if the DefaultTableSeparator character is any
character that doesn't occur in the text being sorted, and it isn't
overridden by an explicit Separator parameter in the .Sort method (or
if the character assigned to Separator also isn't in the text). The
DefaultTableSeparator defaults to the tab character, vbTab... and
presumably the original poster's text didn't contain any tabs.

If the DefaultTableSeparator character does occur in the text, but
it's overridden by a Separator parameter that doesn't occur in the
text, I again get the 9125 error *unless* the Separator is set to
vbTab -- in the latter case there's no error, but no sorting occurs.
<shrug>

You can specify the DefaultTableSeparator with a statement like

Application.DefaultTableSeparator = " "

--
Regards,
Jay Freedman
Microsoft Word MVP Word MVP FAQ site: http://www.mvps.org/word

"Klaus Linke" <fotosatz...@t-online.de> wrote in message

news:a2c0jh$6u8$00$1...@news.t-online.com...

splash

unread,
Jan 22, 2002, 1:41:39 PM1/22/02
to
Balkrishna was "immediately" right. Some of the lines I was trying to sort
were empty; hence, I got error 9125. When I removed the empty lines, the
code ran perfectly. Your whole dialog was very interesting and
enlightening, though. Thanks for all your help, guys.

Splash

"Jay Freedman" <jay.fr...@verizon.net> wrote in message
news:eVh#UAUoBHA.2012@tkmsftngp04...

0 new messages