5.1. Getting Data into
Excel
Before starting, to see any results you
will have to ensure that you have some kind of data being fed
into the Cascade DataHub. If your system isn't set up for this yet, you
can create a local data feed by following the steps outlined
in Section 1.2, “Test with simulated data”.
There are two ways to get data into Excel from
the Cascade DataHub: by setting up a DDEAdvise loop
to receive data automatically, or by using a
DDERequest command from a macro to read data. Deciding which to
use depends on your situation. We suggest you become familiar
with both. For more information about DDE and these commands,
please refer to Section 2.3.1, “DDE Protocol” and
Appendix F, DDE Overview.
5.1.1. Method 1 - Drag and
Drop using DDEAdvise
The
easiest way to get data into Excel is to drag and drop point
names from the DataHub Data Browser directly into the Excel
spreadsheet. This automatically sets up a
DDEAdvise loop between Excel and
the DataHub. DDEAdvise loops update
automatically so you will always see the latest data in your
spreadsheet.
- Right click on the Cascade DataHub system-tray icon and choose
.
In the Properties window,
select
DDE 
.
- Ensure that the box Act as a DDE
server is checked, and that the name
datahub appears in the
DDE Service Name area. If not,
click the Add... button and add
the name datahub.
- Click OK to close the
Properties window.
Right click on the Cascade DataHub system-tray icon and choose
from the pop-up
menu to open the Data Browser.
- Ensure that the Drag & Drop Style
at the bottom of the Data Browser is set to
MS-Office (Excel/Word).
- Open an Excel worksheet.
In the Data Browser, click on the label for a point
and drag it into the Excel worksheet.
You should see the data update in the
worksheet at the same rate it is updating in
the Cascade DataHub.
![[Note]](images/note.gif) | You can select multiple points for drag and drop
by using Shift-click or
Ctrl-click. |
![[Important]](images/important.gif) | When you save and close a spreadsheet
connected to the Cascade DataHub, and then attempt to reopen it, you
may get one or more messages, depending on your security
settings in Excel, or other circumstances. Here's a summary
of each message, and what to do: - This document contains macros. Enable them?
- Click Enable Macros.
- This workbook contains links. Update them?
- Click Update. If
the DataHub is already running, all the links
should then update automatically. If the DataHub
is not running, you will get a
#REF! entry in each cell that
has an advise loop established with the DataHub,
and the next message (see below) will probably
appear.
- Remote data not accessible. Start DataHub?
- Click No. At this
point the best thing to do is close the
worksheet, start the DataHub manually, and then
reopen the worksheet. When you update the
spreadsheet (see above) this time you won't get
any #REF! entries. If,
instead of No you click
Yes at this point,
the DataHub will not start, but instead generate
an error message, and Excel may even crash later
on.
|
5.1.2. Method 2 - Excel Macros using
DDERequest
Sometimes, you
may prefer to manually read data into your spreadsheet,
rather than use a DDEAdvise loop to
constantly accept new values. It may be that you intend to
print reports only a couple of times a day and don't need to
see every point change in between. You can have Excel read
specific data points from the Cascade DataHub at your request by
triggering the DDERequest command from
within a macro.
Using
DDERequest within a macro gives you
complete control over when Excel reads new point values, and
lets you read several data points at one time. To run the
macro, it is convenient to link it to a control button.
This is explained in Add a Control
Button.
- Open a spreadsheet.
- From the menu, select
, and then
.
- In the Macro Name: field of the
Macro dialog box, type the name
GetInput, and press the
Create button.
In the Visual Basic text entry window that comes up,
edit the macro to read as follows:
'
' GetInput Macro
'
Sub GetInput()
mychannel = DDEInitate("datahub", "default")
Application.Worksheets("Sheet1").Activate
newval = DDERequest(mychannel, "my_pointname")
Sheet1.Cells(2, 3) = newval
DDETerminate mychannel
End Sub![[Note]](images/note.gif) | Use the name of your data point
from the Cascade DataHub for
my_pointname. |
![[Note]](images/note.gif) | We use cell
C2 in this example. If you need to use
another cell, you will have to replace (2,
3) with the row and column numbers of the cell
you wish to use. |
- Save and close the Visual Basic text entry
window.
5.1.2.2. Add a Control Button
Activate the Forms toolbar by clicking on the
menu and selecting
, and then
.
- Click on the button icon, and then click in cell
D2. (We use this cell in our example,
but you can choose another cell if you'd like.) An
Assign Macro window should
appear.
Select and
click OK.
Change the label on the button to
"Get".
- For appearance, you can move the button, resize it
with the handles, and change the size of the text by
right-clicking on it and selecting .
- Save the spreadsheet.
5.1.2.3. Receive the data
- Now you're ready to receive the data. Open the
DataHub Data Browser if it is not already open, go to the
default domain, and find the name of the
point.
- Click on the point to highlight it. The point
name should appear in the Selected
Point: field at the top of the Data
Browser.
Type a new value for the point into the
Enter new value: field and press
Enter.
- Go to Excel and click the
Get button. You should see the
data update each time you click the button.