我想獲得從VBA到vb.net的宏轉換,我得到一個類型不匹配的錯誤,並且無法弄清楚。我希望這裏有人能幫助我。VB.net Excel排序
這是代碼。
Sub SortRawData()
Dim oSheet As Excel.Worksheet
Dim oRange As Excel.Range
Try
oSheet = SetActiveSheet(mLocalDocument, "Sheet 1")
oRange = mApplication.ActiveSheet.UsedRange
oRange.Sort(Key1:=oRange("J2"), Order1:=Excel.XlSortOrder.xlAscending, _
Header:=Excel.XlYesNoGuess.xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=Excel.XlSortOrientation.xlSortColumns, _
DataOption1:=Excel.XlSortDataOption.xlSortNormal, _
DataOption2:=Excel.XlSortDataOption.xlSortNormal, _
DataOption3:=Excel.XlSortDataOption.xlSortNormal)
Catch ex As Exception
ErrorHandler.HandleError(ex.Message, ex.Source, ex.StackTrace)
End Try
End Sub
這是從宏觀
Sub SortRawData(ByRef poRange As Range)
Set poRange = Application.ActiveSheet.UsedRange
poRange.Sort Key1:=Range("J2"), Order1:=xlAscending _
, Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
poRange.Sort Key1:=Range("D2"), Order1:=xlAscending, _
Key2:=Range("H2"), Order2:=xlAscending, _
Key3:=Range("L2"), Order3:=xlAscending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
End Sub
任何幫助的代碼,將不勝感激。
謝謝!
那一行,你得到錯誤 – shahkalpesh 2010-01-18 17:03:31
我在 oRange.Sort(Order1:= Excel.XlSortOrder.xlAscending,_ Key1:= oRange(「J2」),_ Header:= Excel.XlYesNoGuess.xlYes,MatchCase:= False,_ 定位:= Excel.XlSortOrientation.xlSortColumns,_ DataOption1:= Excel.XlSortDataOption.xlSortNormal,_ DataOption2:= Excel.XlSortDataOption.xlSortNormal,_ DataOption3:= Excel.XlSortDataOption.xlSo rtNormal) – Lora 2010-01-21 23:23:49