link excell
link excell
link excell
link excell
link excell
link excell link excell link excell link excell link excell link excell link excell link excell
link excell link excell
link excell
Go Back  Xtreme Visual Basic Talk > > > link excell


Reply
 
Thread Tools Display Modes
  #1  
Old 01-15-2004, 03:50 PM
skydiver skydiver is offline
Newcomer
 
Join Date: Jan 2004
Posts: 8
Default link excell


Hi All

Can anyone give me a start point, I have a spreadsheet with a multi user form with text boxes linking cells.

I Have added the excell ref, I just need the workbook link and one text box link

Many thanks in advance
Reply With Quote
  #2  
Old 01-15-2004, 03:59 PM
herilane's Avatar
herilanelink excell herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

I do not understand your question. Please clarify, and also please post the code that you already have.
Reply With Quote
  #3  
Old 01-15-2004, 04:17 PM
skydiver skydiver is offline
Newcomer
 
Join Date: Jan 2004
Posts: 8
Default

Quote:
Originally Posted by herilane
I do not understand your question. Please clarify, and also please post the code that you already have.



Hi herilane

I want to rewrite my vba project, in vb.net
I have this code to start

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Declare Excel object variables and create types
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)
End Sub
but I have this error
C:\Documents and Settings\WindowsApplication1\Form1.vb(53): Statement cannot appear within a method body. End of method assumed.


I dont need to open the excell sheet I just need to write to cells within it
from a user form
I think that if I can start with a textbox that links the spreadsheet I can get started from there

Many thanks
Reply With Quote
  #4  
Old 01-15-2004, 04:29 PM
herilane's Avatar
herilanelink excell herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

I know very little about .Net but it looks like there's a problem in how you refer to worksheets, for one thing. Take a look at post #10 in this thread.

What line is causing the error?
Reply With Quote
  #5  
Old 01-15-2004, 05:23 PM
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

Quote:
Originally Posted by herilane
I know very little about .Net but it looks like...

Herilane knows much more about .Net than she likes to admit to...

Yes, it seems that Post #10 addressing MaggieMay's issues is indeed the same idea. Correcting your code would look something like this:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet Dim xlBooks As Excel.Workbooks ' <-- *** Added *** Dim xlSheets As Excel.Sheets ' <-- *** Added *** xlApp = CType(CreateObject("Excel.Application"), Excel.Application) xlBooks = xlApp.Workbooks ' <-- *** Added *** xlBook = xlBooks.Add ' <-- *** Changed *** xlSheets = xlBook.Sheets ' <-- *** Added *** xlSheet = CType(xlSheets.Item(1), Excel.Worksheet) ' <-- *** Changed ***
The use of CType is not required everywhere. If you use Option Strict On (which is highly recommended, and I am guessing that you are) then the compiler will tell you where you will need to add it.

In your case you need it only in two places:

(1) Surrounding CreateObejct() because the CreateObject() function returns a generic 'As Object' type and so it always needs CType() to cast it into the correct object type, in this case an Excel.Application.

(2) Surrounding xlSheets(1) because the Excel.Worksheets collection is polymorphic, returning either a Worksheet object or a Chart object. The compiler cannot know ahead of time which will come out (even if you do know) and so CType() is required here.

However, for referencing simple objects (that is, non-polymorphic objects) then you will not need CType(). And if you do, the compiler will be sure to tell you when you build!


As for the other corrections, I altered your code te remove the double-object referencing in your code, as was done for MaggieMay.

You may also want to give the VB.Net Office Integration FAQ a read as well. I apologize for it's length, but I do think that reading it will help prevent a lot of grief in the long run...

,
Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb

Last edited by Mike Rosenblum; 01-15-2004 at 07:00 PM.
Reply With Quote
  #6  
Old 01-15-2004, 05:53 PM
skydiver skydiver is offline
Newcomer
 
Join Date: Jan 2004
Posts: 8
Default

Many thanks to both of you for your time
Reply With Quote
  #7  
Old 01-15-2004, 05:56 PM
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

Quote:
Originally Posted by skydiver
Many thanks to both of you for your time

Sure, no problem. (Herilane and I both tip our hat.)

Did it work?

-- Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #8  
Old 01-16-2004, 03:29 AM
skydiver skydiver is offline
Newcomer
 
Join Date: Jan 2004
Posts: 8
Default

Yes Thanks thats working

How can I open an existing workbook ?
Reply With Quote
  #9  
Old 01-16-2004, 03:42 AM
herilane's Avatar
herilanelink excell herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

Not surprisingly, you'd need to use xlBooks.Open instead of xlBooks.Add
Reply With Quote
  #10  
Old 01-16-2004, 04:29 AM
skydiver skydiver is offline
Newcomer
 
Join Date: Jan 2004
Posts: 8
Default

Many thanks again herilane
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Link to a DB2 table using ADOX causes error 1wadd Database and Reporting 1 07-02-2003 01:48 PM
HELP!!! - Past link from VB to a other soft with past link. frech General 2 05-04-2003 07:01 PM
Making a non-underlined link nickg96 Web Programming 1 01-01-2003 03:04 PM
WebBrowser1 copy link to text1 coder2002 Communications 1 01-25-2002 07:41 AM
Link to excell kingesk General 0 10-18-2000 12:50 PM

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
link excell
link excell
link excell link excell
link excell
link excell
link excell link excell link excell link excell link excell link excell link excell
link excell
link excell
 
link excell
link excell
 
-->