12 Replies Latest reply on Jun 1, 2017 6:06 PM by Rick Davin

    Excel - VBA Wrapper PI AF SDK

    StevenLeroy

      Hello everyone,

       

      I am writing to you because i am really lost. My question is the following.

       

      I need to be able to overwrite some attributes values in my AF SERVER when a user click on a button from EXCEL by means of VBA.

       

      I did a lot and a lot of search but unfortunately, i am unable to find out how to add a AFWrapper in Excel so that at last I may use some functions in VBA

       

      I would like to goes throught the PI AF SDK solution. I find out that it is possible but I can't find out how to add the wrapper. Most of the web pages where it explains are no more available when i clicked on the "Step to step link", i got an error.

       

      Can anyone give me some help please. If you can just give  me a "step by step" on how to add a AFWrapper in Excel (VBA), i would be great. I will be able to connect to the server and push my values.

       

      Thank you for your time.

       

      Steven

        • Re: Excel - VBA Wrapper PI AF SDK
          pmartin

          Hi Steven,

           

          Check out this post from a couple years ago: How to install AF Wrapper in ProcessBook

          Keep in mind that the wrapper is only an example.  You will need to add whatever functionality you require to the existing project.

          • Re: Excel - VBA Wrapper PI AF SDK
            Rick Davin

            Hi Steven,

             

            Here's a link from another PI Dev Club member who documented the steps he took.

             

            Here's a disclaimer about AFWrapper.dll:


            The AFWrapper is a learning tool and not a complete product for use in a production environment.  It is offered AS-IS.  The intended audience for this download is experienced .NET developers interested in reviewing an example demonstrating how to create a COM-based add-in using .NET and PI AF SDK within Visual Studio.  The AFWrapper is not intended to be downloaded by VBA programmers with only a beginner’s level of .NET experience.  The DLL as-is performs only a few basic, read-only PI AF SDK calls.  Significant time and resources may be required depending upon the level of customization you wish to include for your particular business requirements.

             

            Also note that the AFWrapper download requires a PI Developers Club license.

              • Re: Excel - VBA Wrapper PI AF SDK
                StevenLeroy

                Hello Rick and Paul,

                 

                I did found these two post explaining how to add the Wrapper but unfortunately when i click on the internal links tof each post i am getting the same error as below :

                 

                Thank you for your quick reply by the way.

                 

                What i am asked to do is really "simple". A user enter a value in a cell (Excel), I have to retrieve the value filled by the user and overwrite a specific attribute value with the one of the cell.

                I have to do this for only one attribute .

                 

                Kind regards,

                 

                Steven

                  • Re: Excel - VBA Wrapper PI AF SDK
                    StevenLeroy

                    Is there a better way, easiest way to achieve my goal.

                     

                    Thank you for your answers.

                     

                    Kind regards,

                     

                    Steven

                    • Re: Excel - VBA Wrapper PI AF SDK
                      Rick Davin

                      Hi Steven,

                       

                      I ask again you fully read the disclaimer I posted earlier.  The AFWrapper example download does NOT write to attributes.  It is a small, simple, read-only example.  Again it is a learning example offered AS-IS and is intended to show experienced .NET developers how to create a COM-visible add-in.  If you are not an experienced .NET developer, you should not be downloading the example.

                       

                      This means if you are able to download it, and you do learn how to install it, you must still know how to modify it to customize it to your needs, as simple as they are.

                      1 of 1 people found this helpful
                        • Re: Excel - VBA Wrapper PI AF SDK
                          StevenLeroy

                          Hello Rick,

                           

                          I read the disclaimer correctly this time. I am not an experience user of .NET. I decided to take this way, even if i am not used to this technology, because i did not find another way to achieve the overwrite of an attribute from Excel.

                           

                          May be there is another way, but i not aware of it, if you know another it will be very helpful.

                           

                          Thank you for your help.

                           

                          Steven

                    • Re: Excel - VBA Wrapper PI AF SDK
                      knightk

                      Steven, if the user has PI Datalink Installed, then the standard Datalink VBA functionality for writing values (piputval) will also write to AF attributes just as easily.

                       

                      The code is just simply

                       

                      result = Application.Run("PIPutVal", AFAttr, ValueCell, "*", AFRoot, ResultCell)

                       

                      AFAttr = the attribute name

                      ValueCell = A cell range

                      AFRoot = the full path to the attribute

                      Result Cell (optional) = a cell range for where the result status message will be written.

                       

                      If I have a list of values I might do something like this....

                       

                      for I = 2 to 10
                          Set ValueCell = Range("B" & I)
                          Set ResultCell = Range("C" & I)
                      
                          AFAttr = Range("A" * I).Value  ' This cell contains the attribute name
                      
                          if ValueCell.Value <> "" then
                                result = Application.Run("PIPutVal", AFAttr, ValueCell, "*", AFRoot, ResultCell)
                          end if
                      
                      next i
                      
                      5 of 5 people found this helpful