Can't you just use PI DataLink for it?
In case not, for whatever reason, here's an example of how you can retrieve sampled data programmatically using the PI-SDK in VBA:
Dim myServer As Server Dim myPoint As PIPoint Dim ipid2 As IPIData2 Dim myValues As PIValues Dim val As PIValue Dim msg As String Set myServer = Servers.DefaultServer Set myPoint = myServer.PIPoints("cdt158") Set ipid2 = myPoint.Data Set myValues = ipid2.InterpolatedValues2("26-jul-2011 10:00", "26-jul-2011 17:00", "30m") msg = "timestamps and values" & vbCrLf For Each val In myValues msg = msg & "ts: " & val.TimeStamp.LocalDate & " - value: " & val.Value & vbCrLf Next val MsgBox msg
Of course you can change this sample code, so that the query parameters (tag name, start time, end time, time interval) are taken from cells in a Excel spreadsheet and the results are output to the spreadsheet.
I hope this helps.
Thanks Daniel, that's what I needed. The user was using DL but he is working on a batch optimization report and the performance was an issue. He is pulling in sampled data on 4 tags and then has 14 Excel calcuations based off of the PI data and also from settings that depend on the material used. Excel was recalculting frequently and taking 3-5 minutes each time. Now it takes about 10 seconds.
Awesome, Jonathan! Thanks for closing the loop.
Please can u show the code in sampled data format I mean
'Sheet1.Cells(9, 9) = Replace("=PISampDat(#SINUSOID#,#10/1/2012#,#10/2/2012#,Sheet1!$N$11,1,#PI#)", "#", """")
in this format I nead the code can you help regarding this, and also using DL Resize in this code.