Solved

DDE between Excel and Visual Basic

Posted on 1998-12-30
11
515 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

939 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now