-
this will open an EXCEL workbook, sort the columns, and close the document (currently does not save changes)
Add a reference to Microsoft Excel x.0 Object Library
Code:
Dim xl As Excel.Application
Dim wb As Excel.Workbook
Set xl = New Excel.Application
Set wb = xl.Workbooks.Open("C:\test4.xls")
With wb.Application
.Columns("B:B").Select
.Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
.Columns("C:C").Select
.Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
wb.Close False
xl.Quit
Set xl = Nothing
Enjoy!
Tom
-
Dear all
I've got completely stuck using excel. I have a programme that creates a text file and then opens it in Excel. What I want to do next is sort columns B and C in ascending order. I've tried a couple of different approaches and every time something goes wrong!!!
I not sure how to control Excel from within vb.
thanks in advance
V