Hi... I have been looking around for this problem, I already found where my problem is but I don't know how to solved.
I'm sure that my problem has to be with Range (I got this from a VBA but I don't know how to translate it to VB).
I'm trying to copy some information from Excel to a Flexgrid, but I have to sort this information before... after that I'm closing Excel but that's not happening, in the task manager I can see the process still running and closing only when I close my program.
vb Code:
Public oApp As Excel.Application Public oWB As Excel.Workbook Public osH As Excel.Worksheet Public oRng As Excel.Range Set oApp = New Excel.Application oApp.Visible = False Set oWB = oApp.Workbooks.Open(Archivo) Set osH = oWB.Sheets(oWB.Sheets.Count) Set oRng = osH.Range("A1") '*** Now I don't know how to continue... oApp.ActiveWorkbook.ActiveSheet.Range(oApp.Selection, oApp.Selection.End(xlDown)).Select oApp.Range(oApp.Selection, oApp.Selection.End(xlDown)).Select CalcRows = oApp.Selection.Rows.Count Clipboard.Clear oApp.ActiveWorkbook.ActiveSheet.Range("A1").Select oApp.ActiveWorkbook.ActiveSheet.Range(oApp.Selection, oApp.Selection.End(xlDown)).Select oApp.ActiveWorkbook.ActiveSheet.Range(oApp.Selection, oApp.Selection.End(xlToRight)).Select oApp.Selection.Sort Key1:=Range(Chr(Asc("A") + RosGL - 1) & "2"), Order1:=xlAscending, _ Key2:=Range(Chr(Asc("A") + RosCoAst - 1) & "2"), Order2:=xlAscending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortTextAsNumbers, DataOption2:=xlSortTextAsNumbers oApp.Selection.Copy FG2.Clear FG2.Rows = CalcRows FG2.Cols = RosCols FG2.Redraw = False FG2.Row = 0 FG2.Col = 0 FG2.ColSel = FG2.Cols - 1 FG2.RowSel = FG2.Rows - 1 FG2.Clip = Replace(Clipboard.GetText, vbNewLine, vbCr) FG2.Col = 1 oApp.DisplayAlerts = False oWB.Close SaveChanges:=False '(App.Path + "\Test1.xls") '"D:\Test.xls" Set oWB = Nothing LogError = "Archivo cerrado" oApp.Quit Set oApp = Nothing




Reply With Quote