H
hans
Hi,
I'm trying to sort an array sheet using vbscript. I've tried several
possibilities, but to no avail.
Below the code I wrote. It seems correct to me, but for some reason my
application just hangs without giving me an error so I don't see what's
going wrong...
(The excel-file exists, so that cann't be the problem)
Const xlWorkSheet = -4167
Const xlLineMarkers = 65
Const xlNormal = -4143
Const xlLeft = -4131
Const xlCenter = -4108
Const xlRight = -4152
Const xlAscending = 1
Const xlYes = 1
Const xlStroke = 2
Const xlSortColumns = 1
sTemplateFile = Server.MapPath("\test") & "\report-template.xls"
sTargetFile = Server.MapPath("\test") & "\report.xls"
'Create an instance of Excel Application
Set oExcelApp = Server.CreateObject("Excel.Application")
'Open template
Set oExcelWkb = oExcelApp.Workbooks.open(sTemplateFile)
'Save copy in download folder
oExcelWkb.SaveAs sTargetFile, xlNormal
'Specify worksheet
set oExcelSht = oExcelWkb.worksheets(1)
' this is what i've tried so far:
oExcelSht.Range("B11:M281").Sort oExcelSht.Range("E11"), 1
oExcelApp.Selection.Sort oExcelApp.Range("E11"), 1, , , , , , 0
oExcelSht.Columns("B:M").Sort oExcelSht.Range("E11"), 1, , , , , , 0
oExcelSht.Range("B11:M281").Sort oExcelSht.Range("E1")
'Calling a macro to sort isn't an option
Set oExcelSht = Nothing
oExcelWkb.close true
Set oExcelWkb = Nothing
oExcelApp.Quit
Set oExcelApp = Nothing
I'm trying to sort an array sheet using vbscript. I've tried several
possibilities, but to no avail.
Below the code I wrote. It seems correct to me, but for some reason my
application just hangs without giving me an error so I don't see what's
going wrong...
(The excel-file exists, so that cann't be the problem)
Const xlWorkSheet = -4167
Const xlLineMarkers = 65
Const xlNormal = -4143
Const xlLeft = -4131
Const xlCenter = -4108
Const xlRight = -4152
Const xlAscending = 1
Const xlYes = 1
Const xlStroke = 2
Const xlSortColumns = 1
sTemplateFile = Server.MapPath("\test") & "\report-template.xls"
sTargetFile = Server.MapPath("\test") & "\report.xls"
'Create an instance of Excel Application
Set oExcelApp = Server.CreateObject("Excel.Application")
'Open template
Set oExcelWkb = oExcelApp.Workbooks.open(sTemplateFile)
'Save copy in download folder
oExcelWkb.SaveAs sTargetFile, xlNormal
'Specify worksheet
set oExcelSht = oExcelWkb.worksheets(1)
' this is what i've tried so far:
oExcelSht.Range("B11:M281").Sort oExcelSht.Range("E11"), 1
oExcelApp.Selection.Sort oExcelApp.Range("E11"), 1, , , , , , 0
oExcelSht.Columns("B:M").Sort oExcelSht.Range("E11"), 1, , , , , , 0
oExcelSht.Range("B11:M281").Sort oExcelSht.Range("E1")
'Calling a macro to sort isn't an option
Set oExcelSht = Nothing
oExcelWkb.close true
Set oExcelWkb = Nothing
oExcelApp.Quit
Set oExcelApp = Nothing