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.Connec
tion")
Set conExcel = CreateObject("ADODB.Connec
tion")
condb.ConnectionTimeout = 100
condb.Open "Driver={SQL Server};Server=...;UID=app
s;PWD=...;
Database=.
.."
' conExcel.Open "Provider=Microsoft.Jet.OL
EDB.4.0;Da
ta Source=" & slocalFile & ";Extended Properties=""Excel 8.0;HDR=YES;"""
Set DB_Conn = CreateObject("ADODB.Connec
tion")
Set DB_RecSet = CreateObject("ADODB.Record
set")
DB_Conn.Open "Driver={SQL Server};Server=...;UID=;PW
D=;Databas
e=..."
Set objExcel = CreateObject("Excel.Applic
ation")
'Setup Recordsets
Set rsData = CreateObject("ADODB.Record
set")
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(sl
ocalFile)
Set cmdData = CreateObject("ADODB.Comman
d")
cmdData.commandtext = "hsp_rpt_GrossMargin"
Set cmdData.ActiveConnection = condb
cmdData.Commandtype = adCmdStoredProc
cmdData.CommandTimeout = 300
cmdData.Parameters("@CustN
umber") = CurrentCustomer
cmdData.Parameters("@Start
Date") = StartingDate
cmdData.Parameters("@StopD
ate") = 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("Temp
late").Cel
ls(NumRows
, iCounter).Value = rsData.Fields(DataRows).Va
lue
testdata = rsData.Fields(DataRows).Va
lue
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,
Randy
Start Free Trial