PDA

View Full Version : Accessing Addin functions with VBA



msentegra
06-06-2008, 10:40 AM
How do I access a function within an Addin using VBA code? I have a PI addin (plant information) that I can use in a spreadsheet to call up plant operational data. I want to use the function in VBA to evaluate lots of data and down load relevant info to my spreadsheet. I know how to use Application or WorkSheetFunction with normal Excel functions, but they don't work with addin functions.:help

Thanks in advance!

grichey
06-06-2008, 10:50 AM
Is it called PI? If you do =PI( , does it give you a list of parameters?

msentegra
06-06-2008, 10:58 AM
Yes it is shown as PI on the toolbar. The full name is PI Datalink version 3.1.6. If I type =PI( into the spreadsheet I only get the value of pi (3.14....).

The version information is:

PI DataLink
Version 3.1.6
PIDLdialogs.xla 3.1.6.0
PITrendXL.xla 3.1.6.0
PIPC32.xll 3.1.6.0
PIPC32.dll 3.1.6.0
MDBTree.ocx 1.5.0.28
PISDK.dll 1.3.4.333
PISDKCommon.dll 1.3.4.333
PISDKDlg.dll 1.5.0.42
PISDKCtl.ocx 1.4.0.22
PITimeServer.dll 1.3.4.333
PIDAArc.dll 3.1.6.1
PIDAXL.dll 3.1.0.5
PIDAEXTTREND.dll 3.1.6.1
PIDO.dll 1.1.1.0
PITrend.dll 3.1.6.1
PIXLTWIZ.dll 3.1.0.5
Copyright ? 2006, OSIsoft, Inc.


I am trying to access the functions in the .XLA files.

Bob Phillips
06-06-2008, 10:59 AM
Use application.run

Application.run "myAddin.xla!PI",4,8

msentegra
06-06-2008, 11:42 AM
On the spreadsheet if I enter:

=PISampDat("GR4_41JI9020", 39569, 39569.04167, "5m", 0, "gila-1tpspi")

I get a value of 115 MW for the plants power output.

In VBA when the statement is entered as:

CTAMW(1) = Application.Run"pidldialogs.xla! PISampDat","GR4_41JI9020",39569,39569.04167,"5m",0,"gila-1tpspi"

I get a compiler error "expected end of statement". Same with this.

CTAMW(1) = Application.Run"pidldialogs.xla!PISampDat(GR4_41JI9020,39569,39569.04167,5m,0,gila-1tpspi)"

I am obviously flying blind in this area.

Bob Phillips
06-06-2008, 12:44 PM
CTAMW(1) = Application.Run("pidldialogs.xla! PISampDat","GR4_41JI9020",39569,39569.04167,"5m",0,"gila-1tpspi")

msentegra
06-06-2008, 12:52 PM
When I use that code I get the error "Application Defined or Object defined error.

On a suggestion from a co-worker I went into the VB tool bar under Tools/References and selected everything related to the PI addin.

Now when I execute the statement

CTAMW(2) = "PITrendXL.xla!PISampDat(PIPoint, StartDate, EndDate, PIInterval, 0, PIServer)"

(The variable names have the same values as earlier.)

I only get the error message "Type mismatch". I think I am getting closer.

Bob Phillips
06-06-2008, 02:17 PM
You should be able to do

CTAMW(2) = PISampDat(PIPoint, StartDate, EndDate, PIInterval, 0, PIServer)