VBScript Automation of Excel Spreadsheet Sorting & Filtering
To the best of my knowledge, it won't work with that construct, because the
arugment to sort isn't a string.
Try this:
xlSelection.Sort xl.Activesheet.Range("A1"),1, _
xl.Activesheet.Range("D1"),,2,,,False,1,True
I left out DataOption1 and DataOption2 because those don't exist before
xl2002.
--
Regards,
Tom Ogilvy
"Steve Munson" wrote in message
...
Tom,
I assumed up front I would need to define the constants
and that didn't do it, so I've now tried placing the
values there, and also tried eliminating the colons, but
to no avail.
In all cases, I've been using a SortString variable to
contain all the details, as there was no other way to
keep the colons in there.
Here's the code snippet:
================================================== ========
==================
SortString = "Key1:=Range(" & Chr(34) & "A1" & Chr(34)
& "), Order1:=1, "
SortString = SortString & "Key2:=Range(" & Chr(34) & "D1"
& Chr(34) & "), "
SortString = SortString & "Order2:=2, Header:=0,
OrderCustom:=1, "
SortString = SortString & "MatchCase:=False,
Orientation:=1, "
SortString = SortString & "DataOption1:=0, DataOption2:=0"
XL.Selection.Sort SortString
================================================== ========
==================
Your thoughts?
Steve
-----Original Message-----
I suspect vbscript does not understand the build in xl
constant definitions.
such as order1:=xlAscending
this would look like order1:=0, but the value of
xlAscending is 1
so the sort is probably being executed, but you are not
seeing any changes.
You need to hard code the values of the constants or
define them in your
code.
This would be true for the autofilter as well.
--
Regards,
Tom Ogilvy
"Stephen Munson" wrote in
message
...
Hello All,
Does anyone know how to code in VBScript the details
surrounding sorting a spreadsheet? I've tried using
the
code you get from recording a macro of doing the sort
manually, and while I don't get syntax erros, I don't
get
any sorting done either. I've tried placing those
details into a string var and then using that as the
parameter, and that fails the same way. I've tried
taking out the ":"'s and maybe I also need to eliminate
the constants too? If anyone has any suggestions,
please let me know, as I have the exact same problem
for
performing an AutoFilter. Thanks!
Steve Munson
.
|