├── GET-POST JSON custom VBA formula.xlsm ├── LICENSE ├── README.md └── VLOOKUP WEB API JSON.VBA /GET-POST JSON custom VBA formula.xlsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denissa4/vlookup-custom-formula-for-web-API-JSON/HEAD/GET-POST JSON custom VBA formula.xlsm -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 nlsql.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vlookup-custom-formula-for-web-API-JSON 2 | Along the way of our commercial B2B SaaS product development, that empowers frontline employees with intuitive text interface to poorly-accessible corporate data to inform and speed business decisions with significant benefits for enterprises, 3 | 4 | WE created a lot of useful and powerful software tools for testing apart of our main product. For example we've created VBA Excel function VLOOKUPWEB, that works same as VLOOKUP but for API JSON format responses. 5 | 6 | https://user-images.githubusercontent.com/31845900/133978214-5707fc84-2b0a-4d94-8063-0f8280689f6e.mp4 7 | 8 | =vlookupweb(1-link-to-api, 2-field-to-query, 3-time-out-in-seconds-between-calls, 4-token-if-needed, 5-body-for-post-or-empty-for-get-request) 9 | 10 | VLOOKUPWEB requires the following inputs: 11 | 1. API link 12 | 2. Field name from JSON response you want to get data 13 | 3. Time-out parameters in seconds (0 for no time-out) 14 | 4. API token if Authorization required (if not leave empty) 15 | 5. Body parameter (if empty it would use GET method. If not empty Body will be sent as POST). 16 | 17 | In order to add this function to your excel: 18 | 1. Open excel 19 | 2. Press Alt + f11 20 | 3. create new module 21 | 4. Copy-paste this code to new module 22 | 5. Save and close VBA editor. 23 | 6. You can use the function as typical formula similar to standard VLOOKUP 24 | 25 | Enjoy! 26 | 27 | subscribe to our LinkedIn https://www.linkedin.com/company/nlsql-com 28 | or Youtube https://www.youtube.com/channel/UC8KtzeNHxhLGVwiOCwvRBkg?sub_confirmation=1 29 | in order to have even more great open-source tools, absolutely free! 30 | -------------------------------------------------------------------------------- /VLOOKUP WEB API JSON.VBA: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------ 2 | 'This function is property of NLSQL Limited, 3 | 'NLSQL is B2B SaaS to empower employees with intuitive text interface to 4 | 'poorly-accessible coporate data to inform and speed business decisions with significant benefits for enterprises. 5 | 'Below code is 100% open-source under MIT Licence, so you can feel free to use it for 6 | 'Commercial use, Modification, Distribution or private use. Except if you are Microsoft =) 7 | 'NLSQL Limited don't have any Liability or Warranties related to your code usage 8 | 'subscribe to our LinkedIn https://www.linkedin.com/company/nlsql-com 9 | 'or Youtube https://www.youtube.com/channel/UC8KtzeNHxhLGVwiOCwvRBkg?sub_confirmation=1 10 | 'in order to have even more great open-source tools, absolutely free 11 | 12 | 'By Denis 13 | 'Date: 06/09/2021 14 | 'info@nlsql.com 15 | 'https://nlsql.com///// 16 | '------------------------------------------------------------------------ 17 | 18 | 'Function works similar to standard Excel VLOOKUP function, 19 | 'so it finds the FIRST value based on API connection and field name from API responce 20 | 21 | Function VLOOKUPWEB(ByVal cell As Range, ByVal txt As String, Optional ByVal pause, _ 22 | Optional ByVal header As String, Optional ByVal postcell As Range) As String ' As Integer 23 | On Error Resume Next 24 | Dim GetResponse As String 25 | FuncDesc = "Function created for Vlookup JSON to excel in a most simpliest way same as using VLOOKUP" 26 | URL = cell.Value 'URL is required to have correct API link including https or http. HTTPS works better for the data security 27 | GetResponse = "" 28 | If URL Like "*http*" Then 29 | 30 | If Not postcell Is Nothing Then 31 | pst = postcell.Value 32 | zapr = "POST" 'support of POST request. Body (5th) Postcell argument is required 33 | Else 34 | pst = "" 35 | zapr = "GET" 'support of GET request. All parameters expected to be in (1st) Cell argument 36 | End If 37 | 38 | Set xmlhttp = CreateObject("MSXML2.XMLHTTP") 'MSXML2.XMLHTTP 39 | xmlhttp.Open zapr, URL, False: DoEvents 40 | xmlhttp.setRequestHeader "Authorization", header 'you can change Authorization to api-key, etc. as required by API provider 41 | xmlhttp.setRequestHeader "Content-Type", "application/json" 'you can add as much headers as needed 42 | xmlhttp.send pst 'send request both POST and GET supported 43 | GetResponse = xmlhttp.responseText 44 | 'MsgBox GetResponse 45 | Set xmlhttp = Nothing 46 | End If 47 | 48 | If pause > 0 Then 49 | t = Timer '3rd argument - Pause in seconds for time-out 50 | Do 51 | DoEvents 52 | If t > Timer Then Exit Do 53 | Loop Until Timer - t > pause 54 | End If 55 | 56 | s = Split(GetResponse, txt) 57 | 58 | If UBound(s) > 0 Then 59 | 60 | ps = Split(s(1), """") 61 | VLOOKUPWEB = ps(2) 62 | 63 | Else: 64 | VLOOKUPWEB = "not available": 65 | 66 | End If 67 | 68 | 69 | 70 | End Function 71 | --------------------------------------------------------------------------------