Converting vba(excel macro) to vbscript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Suggz
    New Member
    • Feb 2012
    • 2

    Converting vba(excel macro) to vbscript

    Hi All,

    Copying code from vba to vbscript did not quite work. I was hoping if anyone could give me a hand. The purpose of the code is to sort the selection so that the smallest value is on the top. I was wondering if there is a way to make this work. Thanks!

    This is the original vba code.
    Code:
    Range("F1").Select
    Application.CutCopyMode = False
    ActiveWorkbook.Worksheets("Sheet3").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet3").Sort.SortFields.Add Key:=Range("F1"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Sheet3").Sort
            .SetRange Range("F1:I49")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    This is vbscript.

    Code:
    oExcel.Range("F1").Select
    oExcel.Application.CutCopyMode = False
    oExcel.ActiveWorkbook.Worksheets("Sheet3").Sort.SortFields.Clear
    oExcel.ActiveWorkbook.Worksheets("Sheet3").Sort.SortFields.Add Key:=Range("F1"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With oExcel.ActiveWorkbook.Worksheets("Sheet3").Sort
            .SetRange Range("F1:I49")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    The vbs script has a "bad index" error starting on line 3.

    With Best Regards,
    Suggz
Working...