473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need Help With Creating An OLE Link

Hello again,

Sorry to repost this request, but I'm under a bit of pressure to find a
quick solution.

All I basically want is an automatically updating link (OLE, not DDE)
between a control in my application and a cell in an Excel spreadsheet. My
control has to automatically receive updates from the spreadsheet cell.

I already know how to access the spreadsheet via the Excel.Application class
but it's the linking of fields I'm having trouble with.

Anybody ?

Thanks,
Gordon.

----------------------------------------------------------------------------
---------------------------------------------------

I am quite new to VB.NET and I would greatly appreciate if anybody could
tell me how to go about creating an OLE link from a label object or text box
object on my Windows Form Application to a cell in an active Excel
spreadsheet.

Many thanks in advance.

Gordon.
Nov 20 '05 #1
9 2553
Hello again,

Sorry to repost this request, but I'm under a bit of pressure to find a
quick solution.

All I basically want is an automatically updating link (OLE, not DDE)
between a control in my application and a cell in an Excel spreadsheet. My
control has to automatically receive updates from the spreadsheet cell.

I already know how to access the spreadsheet via the Excel.Application class but it's the linking of fields I'm having trouble with.

Anybody ?

Thanks,
Gordon.

-------------------------------------------------------------------------- -- ---------------------------------------------------

I am quite new to VB.NET and I would greatly appreciate if anybody could
tell me how to go about creating an OLE link from a label object or text box object on my Windows Form Application to a cell in an active Excel
spreadsheet.

Many thanks in advance.

Gordon.

Nov 20 '05 #2
* "Gordon" <gh*********@btconnect.com> scripsit:
[Nothing new]

If someone would have an answer, he/she would post it...

:-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Thanks for that, Herfried :-)

OK, let's put it another way - how can I set up an event handler for when my
cell in Excel changes ? Here's the code I have so far :

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 xlCell As Excel.Range

xlApp = New Excel.Application

xlBook = xlApp.Workbooks.Add

xlSheet = xlBook.Worksheets.Add

xlCell = xlSheet.Cells(1, 1)

xlApp.Visible = True

xlSheet.Cells(1, 1).Value = "Anything at all"

'Label1.text = xlCell.Value

xlSheet = Nothing

xlBook = Nothing

xlApp = Nothing

End Sub

So, can I either :

(1) set up an event handler for when xlCell changes

or

(2) somehow map Label1.text to xlCell so that Label1.Text isautomatically
updated from xlCell ?

I know I must be missing something very fundamental here , so apologies if
it is to whoever takes up the challenge.

Gordon.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uL**************@tk2msftngp13.phx.gbl...
* "Gordon" <gh*********@btconnect.com> scripsit:
[Nothing new]

If someone would have an answer, he/she would post it...

:-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #4
* "Gordon" <gh*********@btconnect.com> scripsit:
OK, let's put it another way - how can I set up an event handler for when my
cell in Excel changes ? Here's the code I have so far :


Maybe this article helps:

Microsoft Knowledge Base Article - 302814
HOW TO: Handle Events for Excel by Using Visual Basic .NET
<http://support.microsoft.com/default.aspx?scid=kb;en-us;302814>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Thanks Hefrried, that works great. Only one thing left to do :

How can I reference my object Label1 (created as Public WithEvents in
form1.vb) within the event handler xlSheet_Change ? When I try to reference
it, I get a message saying it is not declared. Obviously my scoping of the
variable must be out somehow.

e.g.

Module Module1

'================================================= =================

'Demonstrates Using WithEvents for Event Handling

'================================================= =================

Private xlApp As Excel.Application

Private xlBook As Excel.Workbook

Private WithEvents xlSheet As Excel.Worksheet

Public Sub LoadExcel()

'Start Excel and create a new workbook.

xlApp = CreateObject("Excel.Application")

xlBook = xlApp.Workbooks.Add()

xlBook.Windows(1).Caption = "Uses WithEvents"

'Get references to the worksheet.

xlSheet = xlBook.Worksheets.Item(1)

xlSheet.Activate()

'Make Excel visible and give the user control.

xlApp.Visible = True

xlApp.UserControl = True

End Sub

Private Sub xlSheet_Change(ByVal Target As Excel.Range) Handles
xlSheet.Change

label1.text = xlSheet.Cells(1, 1)
<---------------------------------------------------------------------------
---------------- This is where I get the message 'Label1 is not declared'

End Sub

End Module

Thanks,
Gordon.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
* "Gordon" <gh*********@btconnect.com> scripsit:
OK, let's put it another way - how can I set up an event handler for when my cell in Excel changes ? Here's the code I have so far :


Maybe this article helps:

Microsoft Knowledge Base Article - 302814
HOW TO: Handle Events for Excel by Using Visual Basic .NET
<http://support.microsoft.com/default.aspx?scid=kb;en-us;302814>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #6
* "Gordon" <gh*********@btconnect.nospam> scripsit:
How can I reference my object Label1 (created as Public WithEvents in
form1.vb) within the event handler xlSheet_Change ? When I try to reference
it, I get a message saying it is not declared. Obviously my scoping of the
variable must be out somehow.

e.g.

Module Module1

'================================================= =================

'Demonstrates Using WithEvents for Event Handling

'================================================= =================

Private xlApp As Excel.Application

Private xlBook As Excel.Workbook

Private WithEvents xlSheet As Excel.Worksheet

Public Sub LoadExcel()

'Start Excel and create a new workbook.

xlApp = CreateObject("Excel.Application")

xlBook = xlApp.Workbooks.Add()

xlBook.Windows(1).Caption = "Uses WithEvents"

'Get references to the worksheet.

xlSheet = xlBook.Worksheets.Item(1)

xlSheet.Activate()

'Make Excel visible and give the user control.

xlApp.Visible = True

xlApp.UserControl = True

End Sub

Private Sub xlSheet_Change(ByVal Target As Excel.Range) Handles
xlSheet.Change

label1.text = xlSheet.Cells(1, 1)
<---------------------------------------------------------------------------
---------------- This is where I get the message 'Label1 is not declared'

End Sub

End Module


Quick and Dirty:

Add a public variable of type 'Label' to your module and assign the
label to it (in the form). Then you can change the label's text by
using the variable in the module.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
And how do I assign the label in the module to the label in the form,
Herfried ?

Sorry to be a pain in the neck, but a little quick and dirty example would
do thetrick for me :-)

Gordon.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eY*************@TK2MSFTNGP10.phx.gbl...
* "Gordon" <gh*********@btconnect.nospam> scripsit:
How can I reference my object Label1 (created as Public WithEvents in
form1.vb) within the event handler xlSheet_Change ? When I try to reference it, I get a message saying it is not declared. Obviously my scoping of the variable must be out somehow.

e.g.

Module Module1

'================================================= =================

'Demonstrates Using WithEvents for Event Handling

'================================================= =================

Private xlApp As Excel.Application

Private xlBook As Excel.Workbook

Private WithEvents xlSheet As Excel.Worksheet

Public Sub LoadExcel()

'Start Excel and create a new workbook.

xlApp = CreateObject("Excel.Application")

xlBook = xlApp.Workbooks.Add()

xlBook.Windows(1).Caption = "Uses WithEvents"

'Get references to the worksheet.

xlSheet = xlBook.Worksheets.Item(1)

xlSheet.Activate()

'Make Excel visible and give the user control.

xlApp.Visible = True

xlApp.UserControl = True

End Sub

Private Sub xlSheet_Change(ByVal Target As Excel.Range) Handles
xlSheet.Change

label1.text = xlSheet.Cells(1, 1)
<--------------------------------------------------------------------------- ---------------- This is where I get the message 'Label1 is not declared'
End Sub

End Module


Quick and Dirty:

Add a public variable of type 'Label' to your module and assign the
label to it (in the form). Then you can change the label's text by
using the variable in the module.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #8
* "Gordon" <gh*********@btconnect.nospam> scripsit:
And how do I assign the label in the module to the label in the form,
Herfried ?
You will have to do that in the form, for exampe its 'Load' event
handler (or any other place inside the form):

\\\
Module1.ResultLabel = Me.Label1
///
Sorry to be a pain in the neck, but a little quick and dirty example would
do thetrick for me :-)


Notice that the solution is not "best practice", but it works.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
But I need to do it in MODULE1 in the event handler xlsheet_change(),
something like

me.label1.text = xlsheet.cells(1.1)

But, of course, 'me' isn't defined in MODULE1, so we're back to square one.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uh****************@TK2MSFTNGP09.phx.gbl...
* "Gordon" <gh*********@btconnect.nospam> scripsit:
And how do I assign the label in the module to the label in the form,
Herfried ?


You will have to do that in the form, for exampe its 'Load' event
handler (or any other place inside the form):

\\\
Module1.ResultLabel = Me.Label1
///
Sorry to be a pain in the neck, but a little quick and dirty example would do thetrick for me :-)


Notice that the solution is not "best practice", but it works.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: woodsie | last post by:
i'm looking for a back script that will work in Safari (on mac). the one below works fine in IE and netscape but not safari. <a href="#" onClick="history.go(-1)">go back</a> any help plz?
5
by: Alias | last post by:
Hi Guys , I am trying to create a federated database link between 2 UDB 8.1 databases running on AIX on the same box but under different instances. When i tried this thru the control centre , I...
0
by: Gordon | last post by:
I am quite new to VB.NET and I would greatly appreciate if anybody could tell me how to go about creating an OLE link from a label object or text box object on my Windows Form Application to a cell...
1
by: savvy | last post by:
I want to create a Thumbnail Image from a given large Image and bind it to the Datalist with the datasource being Database. I followed this link given below Creating Thumbnail Images on the fly...
4
by: arad | last post by:
I'm adding some pages to a website for a client and one of the options the client wants is for his employees to be able to login into a separate page for employees only, where they can retrieve...
10
by: David Thielen | last post by:
Hi; I have help html pages for each page of my ASP.NET webapp. So for the page datasource.aspx, I have help\datasource.htm. Bu what I want when the hyperlink is clicked, for it to look for the...
6
by: mike11d11 | last post by:
My program has to tables in it. One is the Accounts table with all personal information and then there is also my Memos table with all the notes for each account. My program displays one record...
33
by: STILL LEARNING | last post by:
I'm not sure if this can even be done, but what prompts the question is my desire to be able to create an "Uber Link" script/code of some sort, such that even if the html page contains nothing but...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.