AnsweredAssumed Answered

How to insert PI Batch Search-function into excel range programmatically with vba

Question asked by ThomasMundt on Feb 14, 2016
Latest reply on Feb 15, 2016 by cvillanua

Hi, I want to use PI Batch Search-functions with Excel.

I am successful when I do it manually, but I want to do it with vba in order to run the code within a ProcessBook display.

I tried it the same way as I successfully did with DataLink-functions.

And how can I know the result-range?

Regards Thomas

 

 

Sub test()

    Dim result_range As Range

    Dim pi_formula As String

 

'    =PIBVSearch(2;"SERVERNAME";"";"";"";"";"*-7 Tag";"";"";"P.0,B.0,S.0,E.0,D.0";473;PIBVUnitBatchSearchMasks("";"*";"*";"";""))

    pi_formula = "=PIBVSearch(2;" & Chr(34) & "SERVERNAME" & Chr(34) & ";" & _

                    Chr(34) & "" & Chr(34) & ";" & Chr(34) & "" & Chr(34) & ";" & Chr(34) & "" & Chr(34) & _

                    ";" & Chr(34) & "" & Chr(34) & ";" & Chr(34) & "*-7 Tag" & Chr(34) & ";" & Chr(34) & "" & _

                    Chr(34) & ";" & Chr(34) & "" & Chr(34) & ";" & Chr(34) & "P.0,B.0,S.0,E.0,D.0" & Chr(34) & _

                    ";465;PIBVUnitBatchSearchMasks(" & Chr(34) & "" & Chr(34) & ";" & Chr(34) & _

                    "*" & Chr(34) & ";" & Chr(34) & "*" & Chr(34) & ";" & Chr(34) & "" & Chr(34) & ";" & Chr(34) & "" & Chr(34) & "))"

    Debug.Print pi_formula

    Set result_range = Range("A1:F2")

    result_range.ClearContents

    result_range.FormulaArray = pi_formula

 

End Sub

 

Outcomes