Working with Excel in VB.net HELP PLEASE!!!!

Mendes

Junior Member
Apr 7, 2003
10
0
0
Here is what I have (Simplified)

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)

xlSheet.Cells(1, 1) = 25
xlSheet.Cells(1, 2) = 27
xlSheet.Cells(1, 3) = 29

xlSheet.Application.Visible = True

xlSheet.SaveAs("C:\Test.xls")
End Sub


==========================

Everything works great.. saves properly. writes to the cells everything. I am trying to find more help on this and obviously vb.net help and MSDN leaves a lot to be determined.

I am trying to find out how to output to a Spreadsheet i already have.
Also how to print the excel spreadsheet.
Where can I look in the future for help on something like this besides this great forum.

Thanks guys!
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
In Excel, go to VB Editor (Alt-F11) and open up the Object Browser (F2). That will let you navigate the Excel object hierarchy. This can be very intimidating if you don't know where to start. Google is a lot of help and the old trick that most everybody programming the Excel object model has used at one time or another is to record a macro doing what you want to do in Excel and then look at the VBA code that is generated. Translating that to VB.NET is straightforward.

In your case Application.Workbooks.Open() is part of what you are looking for. To Print, call PrintOut() on some object that you have, most likely Workbook or Worksheet but the PrintOut() method exists on lots of objects.

You're in for a lot of fun. :) Enjoy!!
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Programming with Excel in .NET is a pain in the ass. I'm writing a C# application at work that has to import data from Excel files, and finding any useful information aboutt he API is nearly impossible.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
If possible, I strongly suggest using VB 6 to interface with Excel. You can make a macro in Excel and copy it directly into VB without changing anything. It's been a while since I did anything with this, but I have a program that does quite a few things between the two. If you want to see it, PM me.