User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 391,661 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,820 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
Views: 3900 | Replies: 2
Reply
Join Date: Feb 2007
Posts: 3
Reputation: Stangman is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Stangman Stangman is offline Offline
Newbie Poster

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

  #1  
Feb 22nd, 2007
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..)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Location: India
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Rep Power: 4
Solved Threads: 13
arjunsasidharan's Avatar
arjunsasidharan arjunsasidharan is offline Offline
Practically a Posting Shark

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

  #2  
Feb 22nd, 2007
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 22nd, 2007 at 11:46 pm.
There is just two ways to live your life.
One is as though nothing is a miracle.
The other is as if everything is.
Reply With Quote  
Join Date: Feb 2007
Posts: 3
Reputation: Stangman is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Stangman Stangman is offline Offline
Newbie Poster

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

  #3  
Feb 23rd, 2007
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)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb VB.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 1:42 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC