Write to excel file.
Write to excel file.
Write to excel file.
Write to excel file.
Write to excel file.
Write to excel file. Write to excel file. Write to excel file. Write to excel file. Write to excel file. Write to excel file. Write to excel file. Write to excel file.
Write to excel file. Write to excel file.
Write to excel file.
Go Back  Xtreme Visual Basic Talk > > > Write to excel file.


Reply
 
Thread Tools Display Modes
  #1  
Old 09-27-2011, 07:49 PM
Solutionz Solutionz is offline
Newcomer
 
Join Date: May 2011
Posts: 17
Default Write to excel file.


Very simple project but i'm getting exception was unhandled after testing code. compiles just fine though. any help is greatly appreciated.

I attached the project as a zip so you can see what im talking about.

code below





Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1
Dim APP As Excel.Application

Dim worksheet As Excel.Worksheet

Dim workbook As Excel.Workbook


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

APP = New Excel.Application

workbook = APP.Workbooks.Open("c:\test\test.xlsx")

worksheet = workbook.Worksheets("sheet1")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
worksheet.Cells(1, 1).Value = TextBox1.Text
End Sub

Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed

workbook.Save()
workbook.Close()
App.Quit()
End Sub

End Class
Attached Files
File Type: zip WindowsApplication1.zip (63.3 KB, 2 views)
Reply With Quote
  #2  
Old 09-28-2011, 06:52 PM
CodeCruncher CodeCruncher is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 355
Default

Worked for me but I needed to add a reference... At the top of your code you have Imports Microsoft.Office.Interop.Excel

If you have a sqiggly line under Imports Microsoft.Office.Interop.Excel

Try going to Project > Add Reference > .Net > Click Microsoft.Office.Interop.Excel and Click OK

Then when you look at the 4 error messages it tells you that you need to Import Microsoft.Office.Interop

Do that or simply remove Excel off the end of the code already there and it worked saving to the file specified.
Reply With Quote
Reply


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Write to excel file.
Write to excel file.
Write to excel file. Write to excel file.
Write to excel file.
Write to excel file.
Write to excel file. Write to excel file. Write to excel file. Write to excel file. Write to excel file. Write to excel file. Write to excel file.
Write to excel file.
Write to excel file.
 
Write to excel file.
Write to excel file.
 
-->