1 Replies - 1022 Views - Last Post: 04 October 2009 - 12:47 PM Rate Topic: -----

#1 miketeebo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 12-August 09

Exporting Values to Excel

Posted 04 October 2009 - 09:36 AM

I am working on a form for my program that will export its values to an excel spreadsheet.

I just started looking for information to help me. This is what I currently have:

Public Class frmResults
	'To open Excel
	Dim ApExcel As Object 
	Dim ApSheet As Object
	Dim ApBook As Object

   Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
		'Creates an object
		ApExcel = CreateObject("Excel.application") 
		' So you can see Excel
		ApExcel.Visible = True 

		'Adds a new book.

		Dim i As Integer
		For i = 1 To 700 + 1
			If ApSheet.Range("Ai").value = "" Then
				ApSheet.Range("Bi").value = FName
				ApSheet.Range("Ci").value = LName
				ApSheet.Range("Di").value = date2
				ApSheet.Range("Ei").value = Age
				ApSheet.Range("Fi").value = Pushup
				ApSheet.Range("Gi").value = Situp
				ApSheet.Range("Hi").value = BComp
				ApSheet.Range("Ii").value = Run
				ApSheet.Range("Ji").value = Score
				ApSheet.Range("Ki").value = Fail
			End If
		Next i
	End Sub
End Class

What I want this to do is to search through a spreadsheet and then add a new line of information when it doesn't fina anything in the "A" column.

Currently I am getting a "COMException was Unhandled" problem on this line of code:


I am hoping that I can get some help figuring out what I can do.

Thanks for your help.

Is This A Good Question/Topic? 0
  • +

Replies To: Exporting Values to Excel

#2 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: Exporting Values to Excel

Posted 04 October 2009 - 12:47 PM

Your code tries to Add a new workbook but don't you want to open an existing workbook?
I am not as familiar with VB.net syntax so here is a link to sample code:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1