Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sorting data and Advance filtering to get totals on a spreadsheet | Excel Discussion (Misc queries) | |||
Excel Sorting / Filtering Colored Cells | Excel Worksheet Functions | |||
Excel - filtering, sorting? | Excel Worksheet Functions | |||
Can i include a vbscript file with an xml spreadsheet? | Excel Discussion (Misc queries) | |||
Excel should allow sorting and filtering based on cell color. | Excel Worksheet Functions |