Solved

DDE between Excel and Visual Basic

Posted on 1998-12-30
11
543 Views
Last Modified: 2013-11-25
I want to connect a Visual Basic picture box with a Excel graphic via DDE. But I don't know which item's name is a graphic in Excel for the linkitem propertie. For example, if I'll want to connect Visual Basic with a Excel cell, i'll push RxCx like linkitem, where x is the cell number. But, with a graphic?? It's possible??
Thanks
0
Comment
Question by:ciri
  • 5
  • 4
  • 2
11 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1453174
Why must it be done using DDE? Why not using OLE Automation?
0
 
LVL 18

Accepted Solution

by:
mdougan earned 100 total points
ID: 1453175
I know it is possible with a chart.  Try this:  Go to excel, highlight the object you want to link to and Copy it.  Then, go to vb, highlight the picture control you want to contain that object and press Edit|Paste Link  this should fill in the link topic with the specific info for the object in question.

MD
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1453176
MDougan is right, this is the way to do it using DDE.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:ciri
ID: 1453177
Well, I want to do this connection in execution time. The idea is that the user don't execute Excel. My program sends the data to Excel, and then create a chart (for do it, i create an excel object). But how i receive this chart?. I thougth in DDE. It's possible?. Is there any other form?. Any form is good. With the excel object?.

Thanks
0
 

Author Comment

by:ciri
ID: 1453178
The code that i use to send the data is the following

Dim Excel As Object
Set Excel = CreateObject("excel.application")
Excel.Visible = false


With Excel
workbooks.Add
range("a2").Select
activecell.formular1c1 = "north"
range("a3").Select
activecell.formular1c1 = "south"
range("a4").Select
activecell.formular1c1 = "east"
range("a5").Select
activecell.formular1c1 = "west"
range("b1").Select
activecell.formular1c1 = "spring"
range("c1").Select
activecell.formular1c1 = "summer"
range("d1").Select
activecell.formular1c1 = "fall"
range("e1").Select
activecell.formular1c1 = "winter"
range("b2").Select
activecell.formular1c1 = "6"
range("c2").Select
activecell.formular1c1 = "35"
range("d2").Select
activecell.formular1c1 = "46"
range("e2").Select
activecell.formular1c1 = "34"
range("e3").Select
activecell.formular1c1 = "24"
range("d3").Select
activecell.formular1c1 = "36"
range("c3").Select
activecell.formular1c1 = "43"
range("b3").Select
activecell.formular1c1 = "32"
range("a3").Select
activecell.formular1c1 = "6"
range("a3").Select
range("b2:e3").Select
selection.autofill destination:=.range("b2:e5")
range("b2:e5").Select
range("a1:e5").Select
calculate
charts.Add
End With

Maybe with a little change I can receive the chart.

0
 
LVL 18

Expert Comment

by:mdougan
ID: 1453179
Lots of ways to do it.  If you want to use DDE then you could create a spreadsheet ahead of time that has sample data in the cells you want to chart, create a chart by highlighting those cells and clicking the chart wizard, copy the chart and paste-link it into your VB program.  Then, you would use DDE to poke data from the user into the cells of the spreadsheet.  If the link between the picture box and the chart is automatic, you'll see the chart/picture box update automatically.  It will be up to you to start Excel (or use an instance that is currently running) and load the pre-defined spreadsheet.

Or, you can use OLE automation.  In OLE automation you would create an object variable  as an Excel.Workbook and/or Excel.Worksheet.  The coding is tricky to include here but there is an example that does almost everything you need in the VB Samples  directory called:

VB\samples\PGuide\GeoFacts

The only thing this example doesn't do is create a chart.  However, a trick I use to see what  the VB code is necessary for creating something in Excel is to go to Excel, turn the Macro recorder on, making sure the language is VBA.  Go through the steps mentioned above to highlight a range of cells and use the chart wizard to create the chart.  Then, stop the macro recorder.  Take a look at the macro code that Excel generated and you can probably almost cut and paste it into your VB app.

Good Luck
MD
0
 
LVL 18

Expert Comment

by:mdougan
ID: 1453180
Oh, once you create your chart in Excel, if you want to view it, then you can either make your Excel object visible or you could then set up a dde link to the chart you created, with a picture box on your VB form.  Just make sure not to set the DDE link properties until after you've created the chart.  The link item property would be pretty standard if you are creating the chart on sheet1, it would always be sheet1.chart1 etc.

Another possibility is to embed the excel object in your form.  But Embeded OLE containers never have worked very well.

Finally, do you really need to use the Excel Chart?  Why not use the chart that comes with VB?  You could always populate this chart with data from Excel using either DDE or OLE (sounds like you're using OLE already)?

MD
0
 

Author Comment

by:ciri
ID: 1453181
mdougan, your DDE option only is valid only if the set of data is always the same, i think?

Respect the OLE automation option, I have tried to execute, but a type mismatch error occurrs in the following line:

Set shtWorld = GetObject("world.xls")

I don't know why.

I like this second option, but I don't have enough time to prove it until next year. See you then.

0
 
LVL 18

Expert Comment

by:mdougan
ID: 1453182
Oh, once you create your chart in Excel, if you want to view it, then you can either make your Excel object visible or you could then set up a dde link to the chart you created, with a picture box on your VB form.  Just make sure not to set the DDE link properties until after you've created the chart.  The link item property would be pretty standard if you are creating the chart on sheet1, it would always be sheet1.chart1 etc.

Another possibility is to embed the excel object in your form.  But Embeded OLE containers never have worked very well.

Finally, do you really need to use the Excel Chart?  Why not use the chart that comes with VB?  You could always populate this chart with data from Excel using either DDE or OLE (sounds like you're using OLE already)?

MD
0
 
LVL 18

Expert Comment

by:mdougan
ID: 1453183
Sorry, I reposted the previous comment by mistake.  That is a bug in their sample code.  That line should read:

Set shtWorld = GetObject(App.Path & "\world.xls")

Happy New Year.

MD
0
 

Author Comment

by:ciri
ID: 1453184
OK. Finally, I have used a DDE link to view the chart, but I create it with OLE. Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question