| | |
VB - How to open an Excel Doc w/ existing data & add data in specific cells?
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 0
Hello!
I'm fairly new to VB, but I have some C, C++ background.
I'm trying to open an existing Excel Document, and add data in specific ranges from Text box inputs in my VB program. However I cannot seem to be able to do this.
The closest I've gotten was to Open the document, and save data, but it erases the items that were already in that document.
Can anyone help me out with this?
Here's what I have so far, haven't incorporated getting the data from the Text boxes yet - as I wanted to ensure the saved document would have the added information, along with the pre-existing data.
Dim oExcel As Excel.Application = New Excel.Application
oExcel.Workbooks.Open("C:\J\Test.xls")
Dim oBook As Object
Dim oSheet As Object
oBook = oExcel.Workbooks.Add
'Add data to cells of the first worksheet in the new workbook.
oSheet = oBook.Worksheets(1)
oSheet.Range("A1").Value = "Last Name"
oSheet.Range("B1").Value = "First Name"
oSheet.Range("A1:B1").Font.Bold = True
oSheet.Range("A2").Value = "Doe"
oSheet.Range("B2").Value = "John"
'Save the Workbook and quit Excel.
oBook.SaveAs("C:\J\Test3.xls")
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
Thank you for any help you can provide!
(it wouldn't surprise me if the above is completely wrong..)
I'm fairly new to VB, but I have some C, C++ background.
I'm trying to open an existing Excel Document, and add data in specific ranges from Text box inputs in my VB program. However I cannot seem to be able to do this.
The closest I've gotten was to Open the document, and save data, but it erases the items that were already in that document.
Can anyone help me out with this?
Here's what I have so far, haven't incorporated getting the data from the Text boxes yet - as I wanted to ensure the saved document would have the added information, along with the pre-existing data.
Dim oExcel As Excel.Application = New Excel.Application
oExcel.Workbooks.Open("C:\J\Test.xls")
Dim oBook As Object
Dim oSheet As Object
oBook = oExcel.Workbooks.Add
'Add data to cells of the first worksheet in the new workbook.
oSheet = oBook.Worksheets(1)
oSheet.Range("A1").Value = "Last Name"
oSheet.Range("B1").Value = "First Name"
oSheet.Range("A1:B1").Font.Bold = True
oSheet.Range("A2").Value = "Doe"
oSheet.Range("B2").Value = "John"
'Save the Workbook and quit Excel.
oBook.SaveAs("C:\J\Test3.xls")
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
Thank you for any help you can provide!
(it wouldn't surprise me if the above is completely wrong..)
Re: VB - How to open an Excel Doc w/ existing data & add data in specific cells?
0
#2 Feb 23rd, 2007
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 0
Re: VB - How to open an Excel Doc w/ existing data & add data in specific cells?
0
#3 Feb 23rd, 2007
![]() |
Similar Threads
- Excel vba 6.0 copy date cells date format (Visual Basic 4 / 5 / 6)
- Open Excel Sheet in Vb.net (VB.NET)
- ootball league table - add data (C)
- ComboBox bind data problem (VB.NET)
- cannot able to open articles or doc files with ie6 (Web Browsers)
- How to Open a word doc from a java application? (Java)
Other Threads in the VB.NET Forum
- Previous Thread: Phone Words Project
- Next Thread: Beginner, Plis assist!
| Thread Tools | Search this Thread |
.net .net2008 2008 access account add advanced application array basic beginner browser button buttons click code combo cpu cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic employees excel exists fade filter forms generatetags html images input intel internet listview mobile module monitor mysql net number objects open panel passingparameters pdf picturebox picturebox2 port position print printing printpreview problem regex reuse right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver storedprocedure survey temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vbnet vista visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





