bradlydraper
New Member
- Joined
- May 13, 2015
- Messages
- 26
Hello everyone,
I am designing a program that will involve writing data to a Closed Workbook. Consider this Closed Workbook (Output.xls) to be a Database, where the Open Workbook will occasionally write data to this Closed workbook for Data Storage purposes. For reasons that are rather lengthy to discuss, I would strongly prefer to avoid Opening the other workbook and turning screen updating to false. Writing to this workbook while it remains closed is an important factor.
I have been exploring ADO/SQL in order to achieve this, and I have made some decent progress but need some help referencing what cells to write to in the Closed Workbook.
This code currently transfers the value from cell "A1" in the Open Workbook to cell "A1" in the Closed Workbook.
The part which I'm struggling to understand is
I'm not sure how to work with Ranges in this format, which I currently understand to be a reference to a table range. What I would like to do is identify the LastRow in the closed workbook and write a value to a cell in that offset row.
Can anyone help me with this problem?
Thanks for the help in advance; I will also post a comment explaining my understanding of this SQL/ADO for those who are unfamiliar with this capability and are interesting in getting started.
I am designing a program that will involve writing data to a Closed Workbook. Consider this Closed Workbook (Output.xls) to be a Database, where the Open Workbook will occasionally write data to this Closed workbook for Data Storage purposes. For reasons that are rather lengthy to discuss, I would strongly prefer to avoid Opening the other workbook and turning screen updating to false. Writing to this workbook while it remains closed is an important factor.
I have been exploring ADO/SQL in order to achieve this, and I have made some decent progress but need some help referencing what cells to write to in the Closed Workbook.
This code currently transfers the value from cell "A1" in the Open Workbook to cell "A1" in the Closed Workbook.
Code:
Sub Example()
Call ClosedWB("C:\Output.xls", _
"Select * From [Sheet1$A1:A1]", _
Sheets("ADO").Range("A1").Value)
End Sub
Sub ClosedWB(WorkbookFullName As String, SQL As String, NewValue As String)
Dim conn As New Connection, rs As New Recordset
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & WorkbookFullName & _
";Extended Properties=""Excel 8.0;HDR=NO;"""
rs.Open SQL, conn, 1, 3
rs.Fields(0).Value = NewValue
rs.Update: rs.Close: conn.Close
End Sub
The part which I'm struggling to understand is
Code:
Select * From [Sheet1$A1:A1]
I'm not sure how to work with Ranges in this format, which I currently understand to be a reference to a table range. What I would like to do is identify the LastRow in the closed workbook and write a value to a cell in that offset row.
Can anyone help me with this problem?
Thanks for the help in advance; I will also post a comment explaining my understanding of this SQL/ADO for those who are unfamiliar with this capability and are interesting in getting started.