Results 1 to 2 of 2

Thread: Completely foxed by excel

  1. #1

    Thread Starter
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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

  2. #2
    Guest

    Post

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width