Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export to Excel

Status
Not open for further replies.

GerardMcL

Technical User
Aug 5, 2004
212
IE
Hello,

Again the switch from VB6 to VB.Net is giving me problems.
I was wondering how I could export a RecordSet and enter it onto an Excel Sheet.

A link to a tutorial or any code you have would be appreciated. Thank you very much.
 
The easiest way is to use a query table. Something like this:

Code:
Public Sub SendData()
        WSID = Environ("COMPUTERNAME")
        UID = Environ("USERNAME")
        Dim intI() As Int16 = {4, 5, 6, 7}

        With XL.ActiveSheet.QueryTables.Add(Connection:= _
       "ODBC;DRIVER=SQL Server;SERVER=ONLINE_SERVER;UID=" & UID & ";WSID=" & WSID & ";DATABASE=weboms;Trusted_Connection=Yes" _
       , Destination:=XL.Range("A1"))
            .CommandText = SQL
            .Name = "ShippingReport"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = Excel.XlCellInsertionMode.xlInsertDeleteCells
            .SavePassword = True
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .Refresh()
        End With
        
        

    End Sub

I hope this helps.


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top