Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBScript Automation of Excel Spreadsheet Sorting & Filtering

Tom,

Your positional argument idea was right on target and has
worked perfectly for the sort. I looked at the object
model within the VBA help, and took note of the argument
list for the sort method, and used that to supply the
needed information. I'll be using that same methodology
to try out the AutoFilter and AdvancedFilter methods.
Thanks once again for providing an extremely valuable
insight that has saved me beaucoup time and effort.

Steve
P.S. Here's the finalized VBScript code snippet for
those that can make use of it (Excel version is Excel
2002):
'
'Select all data & sort by Server, then by descending
Usage
'(Key1, Order1, Key2, Type, Order2, Key3, Order3, Header,
OrderCustom, MatchCase, Orientation, SortMethod,
DataOption1, DataOption2, DataOption3)
'
XL.Range("A1:G" & CStr(Row - 1)).Select
XL.Selection.Sort XL.Activesheet.Range("A1"),1, _
XL.Activesheet.Range("D1"),,2,,,0,1,False,1,0,0

-----Original Message-----
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


.



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting data and Advance filtering to get totals on a spreadsheet Pinlaro Excel Discussion (Misc queries) 4 December 19th 08 05:13 PM
Excel Sorting / Filtering Colored Cells Renegade Excel Worksheet Functions 1 October 17th 08 05:32 PM
Excel - filtering, sorting? feliks27 Excel Worksheet Functions 1 April 25th 06 03:34 AM
Can i include a vbscript file with an xml spreadsheet? Neil.Wills Excel Discussion (Misc queries) 0 September 1st 05 12:34 AM
Excel should allow sorting and filtering based on cell color. Linda Excel Worksheet Functions 3 June 20th 05 05:18 PM


All times are GMT +1. The time now is 08:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"