ItIsHardToProgram
Technical User
Hello,
I have applied a script given to me by SkipVought, who is alot of help always, and I am getting a subscript out of range error on the following line:
The overall code is the following:
It opens excel fine, the file opens fine and there is a worksheet named accordingly to the array. I am a bit mystified as of why this is not working.
By the way, if you haven't figured it out, im running this from an access front end linked to a backend database.
"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.
I have applied a script given to me by SkipVought, who is alot of help always, and I am getting a subscript out of range error on the following line:
Code:
For Each ws In Sheets(Array("BrunoSommaire", "NancySommaire", "JfSommaire"))
The overall code is the following:
Code:
Function TransfertExcelAutomation(strSQL As String, _
sEmplacement As String)
On Error GoTo err_Handler
'Excel object variables
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
Dim sTemplate As String
Dim sTempFile As String
Dim sOutput As String
Dim dbs As DAO.Database
Dim sSQL As String
Dim IRecords As Long
Dim iRow As Integer
Dim iCol As Integer
Dim iFld As Integer
Dim ProjectID As String
Dim ws As Worksheet, r As Range
Dim rst As Recordset
Dim i As Integer
Const cTabOne As Byte = 1
Const cTabTwo As Byte = 2
Const cStartRow As Byte = 3
Const cStartColumn As Byte = 1
iRow = 4
DoCmd.Hourglass True
'Set to break on all errors
Application.SetOption "Error Trapping", 0
'Start with clean file built from template file
'sTemplate = sEmplacement & "\BrunoInterface.xls"
sOutput = sEmplacement & "\BrunoInterface"
If Dir(sOutput) <> "" Then Kill sOutput
'FileCopy sTemplate, sOutput
'Create the Excel Application, Workbook and Worksheet and Database object
Set appExcel = New Excel.Application
appExcel.Visible = True
MsgBox (sOutput)
Set wbk = appExcel.Workbooks.Open(sOutput)
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
If Not rst.BOF Then rst.MoveFirst
'For this template, the data must be placed in the appropriate cells of the spreadsheet
Do
For Each ws In Sheets(Array("BrunoSommaire", "NancySommaire", "JfSommaire"))
For Each r In ws.Range(ws.[A4], ws.[A4].End(xlDown))
If ws.Cells(r.Row, 1) = rst.Fields("IDProjet") Then
ws.Cells(r.Row, 9).Value = rst.Fields("Honoraire utilisé")
End If
Next
Next
rst.MoveNext
Loop Until rst.EOF
rst.Close
exit_Here:
'Cleanup all objects (resume next on errors)
Set wbk = Nothing
appExcel.Quit
Set appExcel = Nothing
Set rst = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
i = 0
Exit Function
err_Handler:
ExportQuery = Err.Description
Resume exit_Here
End Function
It opens excel fine, the file opens fine and there is a worksheet named accordingly to the array. I am a bit mystified as of why this is not working.
By the way, if you haven't figured it out, im running this from an access front end linked to a backend database.
"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.