944,111 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 7118
  • VB.NET RSS
Feb 22nd, 2007
0

VB - How to open an Excel Doc w/ existing data & add data in specific cells?

Expand Post »
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..)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Stangman is offline Offline
3 posts
since Feb 2007
Feb 23rd, 2007
0

Re: VB - How to open an Excel Doc w/ existing data & add data in specific cells?

y don u try postin ur thread in VB Section.. i do hav a solution for dis in VB.net but not for VB..
Last edited by arjunsasidharan; Feb 23rd, 2007 at 12:46 am.
Reputation Points: 347
Solved Threads: 13
Practically a Posting Shark
arjunsasidharan is offline Offline
812 posts
since Aug 2006
Feb 23rd, 2007
0

Re: VB - How to open an Excel Doc w/ existing data & add data in specific cells?

What's the solution for vb.net? I actually might be using VB.net instead, it's the VB Express 2005 edition..? (yea, I'm that new to it I don't even know)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Stangman is offline Offline
3 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Phone Words Project
Next Thread in VB.NET Forum Timeline: Beginner, Plis assist!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC