T
Tim
Hi folks,
When I ran the following code, I got an error message “Run-Time error
‘3265’â€: Item cannot be found in the collection corresponding to the
requested name or ordinal. And the line of code was highlighted
--!rst1("FieldName").Value = objSheet.Range(rst1("CellID").Value).
Please help me to correct it. Thanks in advance.
Tim.
Public Sub x()
Dim objExcel As Excel.Application
Dim objBook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim rst As New ADODB.Recordset
Dim rst1 As ADODB.Recordset
Dim strFile As String
strFile = Dir("c:\test\*xls")
Do While Len(strFile) > 0
Set objExcel = CreateObject("Excel.Application")
Set objBook = objExcel.Workbooks.Open("c:\test\" & strFile,
ReadOnly:=True)
Set objSheet = objBook.Worksheets("Worksheet")
Set rst = fUpdateRst("tbltest")
Set rst1 = fOpenRst("Select FieldName, CellID from tbltest;")
With rst
.AddNew
Do While Not rst1.EOF
!rst1("FieldName").Value =
objSheet.Range(rst1("CellID").Value)
'!LOName = objSheet.Range("C4")
rst.MoveNext
Loop
.Update
.Close
End With
objBook.Close
objExcel.Quit
rst1.Close
Set rst1 = noting
Set objSheet = Nothing
Set objBook = Nothing
Set objExcel = Nothing
Loop
End Sub
When I ran the following code, I got an error message “Run-Time error
‘3265’â€: Item cannot be found in the collection corresponding to the
requested name or ordinal. And the line of code was highlighted
--!rst1("FieldName").Value = objSheet.Range(rst1("CellID").Value).
Please help me to correct it. Thanks in advance.
Tim.
Public Sub x()
Dim objExcel As Excel.Application
Dim objBook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim rst As New ADODB.Recordset
Dim rst1 As ADODB.Recordset
Dim strFile As String
strFile = Dir("c:\test\*xls")
Do While Len(strFile) > 0
Set objExcel = CreateObject("Excel.Application")
Set objBook = objExcel.Workbooks.Open("c:\test\" & strFile,
ReadOnly:=True)
Set objSheet = objBook.Worksheets("Worksheet")
Set rst = fUpdateRst("tbltest")
Set rst1 = fOpenRst("Select FieldName, CellID from tbltest;")
With rst
.AddNew
Do While Not rst1.EOF
!rst1("FieldName").Value =
objSheet.Range(rst1("CellID").Value)
'!LOName = objSheet.Range("C4")
rst.MoveNext
Loop
.Update
.Close
End With
objBook.Close
objExcel.Quit
rst1.Close
Set rst1 = noting
Set objSheet = Nothing
Set objBook = Nothing
Set objExcel = Nothing
Loop
End Sub