I have a Excel template that I have some formulas in I want to export from a Access Query into this excel spread sheet. I found some code in this forum that I have modified to fit my spread sheet. When I run the process I get a "Subscript out of range" error 9
I get the error on the very first line when trying to load the data.
I plan on using some subscript to change the row but need to find out why I'm getting the subscript out of range error.
Any help would be appreciated.
Code:
Dim fichier As String
Dim CurMatch As DAO.Recordset
reportfolder = "C:\tempfolder"
fichier = "\Scoring Template1.xlsx"
Dim x1Obj As Object
Set x1Obj = CreateObject("excel.application")
Dim fso As Object
Set fso CreateObject("Scripting.FileSystemObject")
fso.CopyFile Application.CurrentProject.path & "\scoring template.xlsx", reportfolder & fichier, True
x1Obj.workbooks.Open reportfolder & fichier
' script to fill in data
strsql = "select * from currentmatchexcel"
Set CurMatch = db.OpenRecordset(strsql)
Do While Not CurMatch.EOF
[B]x1Obj.sheets("Data").Range("a2").Value = CurMatch("alias")[/B]
xlObj.sheets("data").Range("B2").Value = CurMatch("Class")
x1Obj.sheets("data").Range("C2").Value = CurMatch("Time1")
x1Obj.sheets("data").Range("E2").Value = CurMatch("Misses1")
x1Obj.sheets("data").Range("F2").Value = CurMatch("Penelties1")
x1Obj.sheets("data").Range("G2").Value = CurMatch("Bonus1")
x1Obj.sheets("data").Range("I2").Value = CurMatch("Time2")
x1Obj.sheets("data").Range("J2").Value = CurMatch("Misses2")
x1Obj.sheets("data").Range("K2").Value = CurMatch("Penelties2")
x1Obj.sheets("data").Range("L2").Value = CurMatch("Bonus2")
x1Obj.sheets("data").Range("O2").Value = CurMatch("Time3")
x1Obj.sheets("data").Range("P2").Value = CurMatch("Misses3")
x1Obj.sheets("data").Range("Q2").Value = CurMatch("Penelties3")
x1Obj.sheets("data").Range("R2").Value = CurMatch("Bonus3")
x1Obj.sheets("data").Range("U2").Value = CurMatch("Time4")
x1Obj.sheets("data").Range("V2").Value = CurMatch("Misses4")
x1Obj.sheets("data").Range("W2").Value = CurMatch("Penelties4")
x1Obj.sheets("data").Range("X2").Value = CurMatch("Bonus4")
x1Obj.sheets("data").Range("AA2").Value = CurMatch("Time5")
x1Obj.sheets("data").Range("AB2").Value = CurMatch("Misses5")
x1Obj.sheets("data").Range("AC2").Value = CurMatch("Penelties5")
x1Obj.sheets("data").Range("AD2").Value = CurMatch("Bonus5")
x1Obj.sheets("data").Range("AG2").Value = CurMatch("Time6")
x1Obj.sheets("data").Range("AH2").Value = CurMatch("Misses6")
x1Obj.sheets("data").Range("AI2").Value = CurMatch("Penelties6")
x1Obj.sheets("data").Range("AJ2").Value = CurMatch("Bonus6")
CurMatch.MoveNext
Loop
End If
I plan on using some subscript to change the row but need to find out why I'm getting the subscript out of range error.
Any help would be appreciated.
Comment