如何将如下语句转为VB呢?
Selection.Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
        :=xlPinYin

解决方案 »

  1.   

    创建Excel对象来做:Private Const xlDescending As Long = 2
    Private Const xlGuess As Long = 0
    Private Const xlTopToBottom As Long = 1
    Private Const xlPinYin As Long = 1Sub sortData()
        Dim xls As Object
        Set xls = CreateObject("excel.application")
        xls.Visible = True
        xls.Workbooks.Open "c:\test.xls"
        
        With xls.ActiveWorkbook.Sheets("Sheet1")
            .Range(Cells(1, 1), Cells(50, 50)).sort Key1:=.Range("B1"), _
            Order1:=xlDescending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, _
            Orientation:=xlTopToBottom, SortMethod:=xlPinYin
        End With
        
        Set xls = Nothing
    End Sub
      

  2.   

    .Range(Cells(1, 1), Cells(50, 50)).sort .....
    ----------
    假设Select的是Cells(1,1)到Cells(50,50)
      

  3.   

    在程序中我已经引进了excel .对与xlDescending, xlGuess等还是保错,说明这些方法还没有引进来.
    还有,我是在新建的excel时,使用这些语句的
      

  4.   

    Selection.Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
            :=xlPinYin