Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
Go Back  Xtreme Visual Basic Talk > > > Worksheets, adding/selecting/filling


Reply
 
Thread Tools Display Modes
  #1  
Old 12-13-2011, 07:54 AM
PeetSoft's Avatar
PeetSoft PeetSoft is offline
Centurion
 
Join Date: Jun 2003
Location: HHW - the Netherlands
Posts: 184
Default Worksheets, adding/selecting/filling


In my app I need to fill an excel file with some data.
On change of customer the data needs to be on another worksheet, sheet renamed and so on.

The workbook now has 19 sheets (wSheet.Add(,,16), the first worksheet gets renamed to custno. and the sheets gets filled.

But whatever I try, I can't get onto the other worksheets.

All I Googled seem to raise errors; following code is part of a nested 'If'

Code:
Dim excel As New Microsoft.Office.Interop.Excel.Application Dim wBook As Microsoft.Office.Interop.Excel.Workbook Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet If w < 1 Then wBook = excel.Workbooks.Add() wSheet = wBook.Sheets.Add(, , 16) excel.Visible = True Else wSheet = wSheet.Next End If wSheet.Name = shtName.ToString

will result in: Object reference not set to an instance of an object.
Sheet.Select: COM incompatibility

using VS2010 express, Office 2003

t.i.a.

Peet
__________________
-----------------------------------------------------
If debugging is the art of removing bugs, then
programming must be the art of inserting them.
I do comply with Flyguy's signature (If he still had one)
Reply With Quote
  #2  
Old 12-15-2011, 06:44 AM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Peet,

I'm not on a computer with VS installed but in general we need to cast the Excel object worksheet. So please see if the following works for You:

Code:
wsSheet = CType(wBook.Sheets.Add(, , 16), Excel.Worksheet)

If You still have issues then please provide us with the code where You iterate through the collection of worksheets.
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
Reply

Tags
excel, vb.net, worksheet


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
Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
 
Worksheets, adding/selecting/filling
Worksheets, adding/selecting/filling
 
-->