CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 17

Threaded View

  1. #1
    Join Date
    Jul 2007
    Posts
    69

    Question Vbscript, sql & write/add record to existing excel file

    Hi, Posted the question before - but could not get it going!

    Can someone please Assist, as i need this to work it's part of my project!

    VBscript, I'm executing a SQL command then with the result data append/add the row to an existing excel file.
    Please anyone please Assist!

    Scipt
    Code:
    Dim objXL 
    Dim File_name
    Option WScript
    
    File_name="\\srv08-za063\source\test.xls" 
    Set objXL = WScript.CreateObject("Excel.Application") 
    Set wb = objXL.Workbooks.Add 
    Set ws = objXL.Worksheets(1) 
    r = 2 
    objXL.Visible = False 
    
    
    Set objConn = CreateObject( "ADODB.Connection")
    Set resultSet = CreateObject ("ADODB.RecordSet")
    objConn.Open fcCustom.Value(Process.Company, "Connections\FCDB")
    strSQL = "select id,ProcessID from dbo.fcEventArchive where EventHistID = 2523"
    resultSet.Open strSQL, objConn, 1, 2
    
    On Error Resume Next 
    resultSet.MoveFirst 
    
    Do While Not resultSet.eof 
    ws.Cells(r, 1).Value = (resultset(0)) 
    ws.Cells(r, 2).Value = (resultset(1)) 
    resultSet.MoveNext 
    r = r + 1 
    Loop 
    
    resultSet.Close
    objConn.Close
    Set resultSet = Nothing
    Set objConn = Nothing
    Last edited by Shuja Ali; January 7th, 2008 at 05:49 AM. Reason: Added Code Tags.

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

Featured