Advertisement

05.08.2008 at 05:05AM PDT, ID: 23385731
[x]
Attachment Details

Copy data to specific cell locations in Excel spreadsheet

Asked by ratkinso666 in MS SQL DTS, Microsoft Excel Spreadsheet Software, VB Script

Tags: microsoft, sql enterprise manager, vb6

Hi all, I am mostly done with this, but can't seem to get the part where I copy my data to a specific cell location on an Excel spreadsheet.  Normally I would just do an add new and copy my data to there.  BUT with this one, I have a specific tab name "template" and a specific location to start copying my data Y5, I can't do an add new here because it messes up the other formulas in the spreadsheet.  So, I have to start my data at Y5 to AC5 for the first line and then go down from there.  Here is what I have so far..

'Setup Connections
   Set condb = CreateObject("ADODB.Connection")
   Set conExcel = CreateObject("ADODB.Connection")
   condb.ConnectionTimeout = 100
   condb.Open "Driver={SQL Server};Server=...;UID=apps;PWD=...;Database=..."
'   conExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & slocalFile & ";Extended Properties=""Excel 8.0;HDR=YES;"""
   Set DB_Conn = CreateObject("ADODB.Connection")
   Set DB_RecSet = CreateObject("ADODB.Recordset")
   DB_Conn.Open "Driver={SQL Server};Server=...;UID=;PWD=;Database=..."
Set objExcel = CreateObject("Excel.Application")

   'Setup Recordsets
   Set rsData = CreateObject("ADODB.Recordset")

   sSQL = "SELECT  CustomerNumber from GMCCustomers"
   DB_RecSet.Open sSQL, DB_Conn
Do Until DB_RecSet.EOF
   CurrentCustomer = DB_RecSet(0)
    oFileSys.CopyFile slocalTemplate, slocalFile

Set objExcelMaster = objExcel.Workbooks.Open(slocalFile)
   Set cmdData = CreateObject("ADODB.Command")
   cmdData.commandtext = "hsp_rpt_GrossMargin"
   Set cmdData.ActiveConnection = condb
   cmdData.Commandtype = adCmdStoredProc
   cmdData.CommandTimeout = 300
   cmdData.Parameters("@CustNumber") = CurrentCustomer
   cmdData.Parameters("@StartDate") = StartingDate
   cmdData.Parameters("@StopDate") = StoppingDate
   Set rsData = cmdData.execute
     
   
   NumRows = 5
   
   '  This is the section that is not correct...
   While Not rsData.EOF
      DataRows = 0
      For iCounter = 24 To 28
           objExcelMaster.Worksheets.Item("Template").Cells(NumRows, iCounter).Value = rsData.Fields(DataRows).Value
           testdata = rsData.Fields(DataRows).Value
           DataRows = DataRows + 1
      Next
      NumRows = NumRows + 1
   Wend
   
   objExcelMaster.SaveAs strReportsPath & Mid(CurrentCustomer, 1, 8) & ".xls"
   objExcelMaster.Close
   objExcel.quit

      DB_RecSet.movenext
Loop

If you have further questions please ask.
Thanks,
RandyStart Free Trial
[+][-]05.08.2008 at 06:01AM PDT, ID: 21524205

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.08.2008 at 06:15AM PDT, ID: 21524302

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.08.2008 at 06:32AM PDT, ID: 21524472

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.08.2008 at 06:33AM PDT, ID: 21524485

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.08.2008 at 06:44AM PDT, ID: 21524586

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.08.2008 at 06:45AM PDT, ID: 21524609

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL DTS, Microsoft Excel Spreadsheet Software, VB Script
Tags: microsoft, sql enterprise manager, vb6
Sign Up Now!
Solution Provided By: sungenwang
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.08.2008 at 06:58AM PDT, ID: 21524713

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.08.2008 at 06:58AM PDT, ID: 21524717

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628