![]() |
Trouble reading to object
Hi! I have a sub that opens a workbook. I then try to read values from this
workbook. However I get the error: 1004 Program or obect defined error at the very end of the code. What is wrong here? Please help me out! Public Sub readFile() 'secID As String Dim i As Integer Dim j As Integer Dim iNrOfIns As Long Dim secID As String secID = "Hej på dig" Dim str As String Workbooks.Open "X:\SCD_RiskManager_Pos\RMDBII\test.xls" Workbooks("test.xls").Activate Dim oFxOptionsFile As Object Set oFxOptionsFile = Workbooks(ActiveWorkbook.Name).Sheets(ActiveSheet. Name) oFxOptionsFile.Range("A2").Activate iNrOfIns = oFxOptionsFile.Range(ActiveCell, ActiveCell.End(xlDown)).Rows.Count For i = 2 To 10 str = oFxOptionsFile.Cells(i, 0) |
Trouble reading to object
Arne,
There is no 0th column: str = oFxOptionsFile.Cells(i, 0) should be (for column A) str = oFxOptionsFile.Cells(i, 1) for column B: str = oFxOptionsFile.Cells(i, 2) HTH, Bernie MS Excel MVP "Arne Hegefors" wrote in message ... Hi! I have a sub that opens a workbook. I then try to read values from this workbook. However I get the error: 1004 Program or obect defined error at the very end of the code. What is wrong here? Please help me out! Public Sub readFile() 'secID As String Dim i As Integer Dim j As Integer Dim iNrOfIns As Long Dim secID As String secID = "Hej på dig" Dim str As String Workbooks.Open "X:\SCD_RiskManager_Pos\RMDBII\test.xls" Workbooks("test.xls").Activate Dim oFxOptionsFile As Object Set oFxOptionsFile = Workbooks(ActiveWorkbook.Name).Sheets(ActiveSheet. Name) oFxOptionsFile.Range("A2").Activate iNrOfIns = oFxOptionsFile.Range(ActiveCell, ActiveCell.End(xlDown)).Rows.Count For i = 2 To 10 str = oFxOptionsFile.Cells(i, 0) |
All times are GMT +1. The time now is 06:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com