Writing to excel sheet
Writing to excel sheet
Writing to excel sheet
Writing to excel sheet
Writing to excel sheet
Writing to excel sheet Writing to excel sheet Writing to excel sheet Writing to excel sheet Writing to excel sheet Writing to excel sheet Writing to excel sheet Writing to excel sheet
Writing to excel sheet Writing to excel sheet
Writing to excel sheet
Go Back  Xtreme Visual Basic Talk > > > Writing to excel sheet


Reply
 
Thread Tools Display Modes
  #1  
Old 02-25-2005, 03:13 AM
Nick_1 Nick_1 is offline
Freshman
 
Join Date: Jan 2005
Posts: 44
Default Writing to excel sheet


Any one know why i am getting this error
Code:
An unhandled exception of type 'System.MissingMemberException' occurred in microsoft.visualbasic.dll

Additional information: Public member 'Workbook' on type 'ApplicationClass' not found.
my code is
Code:
Dim xlapp As New Excel.Application Dim xlbook As Excel.Workbook = xlapp.Worksbooks.Open("E:\claim rejection report") Dim xlsheet As Excel.Worksheet = CType(xlbook.Worksheets(2), Excel.Worksheet) 'next two lines are just for testing purposes txtdate.Text = xlsheet.Cells(1, 3965).value xlapp.Visible = True 'code to go in 'clean up xlbook.close(saveChanges:=True) xlapp.Quit() xlapp = Nothing xlbook = Nothing xlsheet = Nothing GC.Collect()

txtdate is a textbox filled from a database.
When i get this working the real agenda is to find the last row in the sheet and append a new row each time a button is pressed.
Thanks in advance
Reply With Quote
  #2  
Old 02-25-2005, 03:33 AM
zeno_nz's Avatar
zeno_nz zeno_nz is offline
Regular
 
Join Date: Oct 2004
Location: New Zealand
Posts: 99
Default

while I do not use .net and the code was witten using vb6

i've used the excel object extensively and have found late binding the most successful (you don't have to reference and distribute the excel object)

Hope this is of some help
Code:
private  mobjXL as object
Set mobjXL = CreateObject("Excel.Application")
mobjXL.Application.Workbooks.Open("E:\claim rejection report")

' do stuff here

' kill the object
mobjXL.quit
set  mobjXL = nothing
__________________
Two aerials meet on a roof, fall in love get married. The ceremony wasn't much but the reception was brilliant.
Reply With Quote
  #3  
Old 02-25-2005, 04:42 AM
Nick_1 Nick_1 is offline
Freshman
 
Join Date: Jan 2005
Posts: 44
Default

Thanks for the quick responce however
your solution brings up new problems with direct x.
Now i fixed my problem (it was just a typo) but a new one has come about
Code:
An unhandled exception of type 'System.InvalidCastException' occurred in WindowsApplication1.exe

Additional information: Specified cast is not valid.
This has to do with the ctype i think
Code:
Dim xlapp As New Excel.Application Dim xlbook As Excel.Workbooks = xlapp.Workbooks.Open("E:\claim rejection report") Dim xlsheet As Excel.Worksheet = CType(xlsheet.Worksheet(2), Excel.Worksheet) txtdate.Text = xlsheet.Cells(1, 3965).value xlapp.Visible = True 'clean up xlbook.Close() xlapp.Quit() xlapp = Nothing xlbook = Nothing xlsheet = Nothing GC.Collect()
Reply With Quote
  #4  
Old 02-25-2005, 07:02 AM
Dennis DVR's Avatar
Dennis DVRWriting to excel sheet Dennis DVR is offline
Back in the Game

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Manila Philippines
Posts: 3,576
Default

__________________
Avatar by Lebb

[Posting Guidelines] [Standards & Practices Tutorial] [Participate here effectively]
Our knowledge can only be finite, while our ignorance must necessarily be infinite. Karl Popper
Reply With Quote
  #5  
Old 02-25-2005, 07:51 AM
Nick_1 Nick_1 is offline
Freshman
 
Join Date: Jan 2005
Posts: 44
Default

i had already read this along with other tutorial from mike i think when reading them that i have things sussed only to be greated by a new error. going to leav it for today come back to it tomorrow with a fresh head thanks for the help guys
Nick_1
Reply With Quote
  #6  
Old 02-25-2005, 10:14 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Ok... a couple of things...

First, turn on 'Option Strict On'. Put it at the top of your module... Better yet, make it a Project-Wide setting. Goto Alt|Tools|Options... then choose the 'Projects' and set 'Option Strict' to "On".

If you do this, you'll get a big squiggly line under:
Code:
Dim xlsheet As Excel.Worksheet = CType(xlsheet.Worksheet(2), Excel.Worksheet)
You must have been tired, I think. You meant to get the Worksheets(2) within the xlbook. However, you left off the last "s" on "Worksheets" and used "xlsheet" instead of xlbook! I think you meant to use:
Code:
Dim xlsheet As Excel.Worksheet = CType(xlbook.Worksheets(2), Excel.Worksheet)
Hopefully this will do the trick!

,
Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #7  
Old 02-28-2005, 12:28 AM
Nick_1 Nick_1 is offline
Freshman
 
Join Date: Jan 2005
Posts: 44
Default

Thanks guys Got it working now your sugestions were spot on. I was tired mike I left it alone all weekend and things look a lot clearer now thanks again.
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
Writing to excel sheet
Writing to excel sheet
Writing to excel sheet Writing to excel sheet
Writing to excel sheet
Writing to excel sheet
Writing to excel sheet Writing to excel sheet Writing to excel sheet Writing to excel sheet Writing to excel sheet Writing to excel sheet Writing to excel sheet
Writing to excel sheet
Writing to excel sheet
 
Writing to excel sheet
Writing to excel sheet
 
-->