The Ultimate OPC Enabling Technology
spacer
HomeFeaturesDownloadLicensingSupportPartnersCompany
OPCとExcel
エクセルマクロヘルプ
Introduction
You are free to use the following Macro examples in your own Excel applications. These macros provide useful shortcuts and hints that you can use to create interactive Excel application that read and write data with the DataHub.

Review of DataHub to Excel Connection Options

Overview
These Excel macros are based on a 100 row x 40 column table of data in Sheet1 of the worksheet, starting at cell position A1. We have tried to make these macros generic so you can easily modify them to suit your needs.

Macros to help configure Excel to read data from the DataHub (using DDEAdvise)

1. Macro to attach array data in the DataHub, one array per row, to a table of values in Excel.
It is often more convenient to transmit large sets of Excel data as an array because this significantly reduces the bandwidth requirements and increases the speed of transmission. This macro sets up DDEAdvise loops from the DataHub to Excel, so that each row of the table is linked to an array point in the Cascade DataHub. Normally, you would only need to run this macro once, when you are designing your spreadsheet.

2. Attach individual point data in the Cascade DataHub, one point per cell, to a table of values.
This macro sets up DDEAdvise loops from the DataHub to Excel, so that each cell in the table is linked to a point in the Cascade DataHub. Normally, you would only need to run this macro once, when you are designing your spreadsheet.

Macros to write data from Excel - User initiated write on demand (using DDEPoke)

The following macros are useful for writing data out from Excel on demand, in other words, the user decides when to write the data and initiates the write by running one of these macros (usually from an assigned button click).

3. Transmit array data, one array per row to points in the Cascade DataHub.
This macro would be triggered any time you wanted to write data from the table in Excel to the Cascade DataHub. This macro would write each row of the table as an array point in the DataHub. The macro transmits all rows of the table, one after another.

4. Transmit individual point data, one point per cell to points in the Cascade DataHub.
This macro would be triggered any time you wanted to write data from the table in Excel to the Cascade DataHub. This macro would write each cell in the table to a single point in the DataHub. The macro transmits all cells in the table, one after another.

Macros to write data from Excel - Automatic write on value change (using DDEPoke)

The following macros can be useful for automatically transmitting data from Excel into the Cascade DataHub.

5. Whenever the user enters a new value, check to see if that cell is named. If so, emit the new value to a Cascade DataHub point of the same name.
The subroutine name "Worksheet_Change" is special - it is called by Excel whenever a change occurs on the Worksheet due to user input or recalculation (though not a change due to a DDE message, see #7 below).

6. Determine that a cell within a particular named range has changed through user input, and transmit the contents of the range to the Cascade DataHub.
This macro is useful because you do not have to configure each cell you want to write out to the DataHub. If the cell that is changed lies within a defined range, then all values in that range are automatically written out to the DataHub.

Other useful Excel macros

7. Cause a macro to run if a DDE message is received for a particular point.
The following two macros illustrate how to set up a linkage so that a macro is run every time a cell value is updated by a DDE message. In our example below, we assume there is a cell being updated with a point from the DataHub. We define a linkage, so that a macro is run every time this point is updated.

詳細

 
Copyright © 1995 - 2010, Cogent Real-Time Systems Inc. All rights reserved. Legal Notice.