How to Install Python on Windows 10

Do you want to learn how to install Python 3.10 on Windows 10 Computer in depth so you can install it in any computer without help. Then, you are at the right place, just keep reading till the end and you will be able to do it yourself. What is Python? Python is a powerful, […]

Continue reading...

Recent Post

18 Feb 2025

How to Fetch Intraday Data of Stocks for Any Interval Period using Python

Continue reading

Featured Post

25 May 2023

How to Fetch Stock’s Historical Data From NSE India in Python

Continue reading

In the dynamic world of financial markets, having access to real-time or near real-time data is paramount for informed decision-making. For traders and investors focusing on the Indian equity derivatives market, the National Stock Exchange (NSE) website is a primary source of official data. While the NSE website provides this data, manually extracting it can be tedious and time-consuming. This guide will walk you through a powerful solution: automating the data retrieval process using Excel VBA.

We’ll demonstrate how to fetch NIFTY Index futures data directly from the NSE India website into your Excel spreadsheet. This will empower you to analyze trends, backtest strategies, and create custom dashboards with minimal effort.

Introduction to Web Scraping with VBA

Web scraping is the process of extracting data from websites. While dedicated web scraping tools exist, Excel VBA offers a convenient and accessible way to perform basic web scraping tasks, especially when the data is presented in a structured format like tables.

Our VBA script will leverage the MSXML2.XMLHTTP object to make an HTTP request to the NSE website and the MSHTML.HTMLDocument object to parse the HTML response and extract the desired data. This approach is robust and allows for targeted data extraction.

Prerequisites

Before we dive into the technical details, ensure you have the following:

  1. Microsoft Excel: This guide is designed for Microsoft Excel (preferably 2010 or later versions).
  2. Basic understanding of Excel: Familiarity with worksheets, cells, and basic formulas.
  3. Basic understanding of VBA: While this guide provides detailed explanations, a rudimentary understanding of VBA concepts will be beneficial.

Step 1: Enable Developer Tab in Excel

  1. Open Excel.
  2. Go to File > Options.
  3. Select Customize Ribbon.
  4. Check the box for Developer in the right pane.
  5. Click OK.

Step 2: Insert a New Module in VBA Editor

  1. Click on the Developer tab.
  2. Click on Visual Basic to open the VBA editor.
  3. In the VBA editor, go to Insert > Module.
  4. A new module window will appear for code entry.

Step 3: The VBA Script

In the new module, paste the following VBA code:

Step 4: Run the VBA Macro

  1. Close the VBA editor to return to Excel.
  2. Press Alt + F8 to open the Macro dialog box.
  3. Select fetch_index_json_data from the list.
  4. Click Run.

The macro will fetch the latest Index Future data for NIFTY from the NSE website and populate it into Sheet1 with columns for all index future data.

Conclusion

In essence, automating NSE futures data fetching with Excel VBA is a powerful step towards more efficient market analysis. This guide has provided you with the script and knowledge to get started. While websites evolve, understanding these core principles ensures you can adapt and continue to leverage timely, accurate data for smarter trading and investment decisions.

Here is the link for you, if you want to Fetch Option Chain Data from NSE India using VBA

You can explore more informative videos at my YouTube Channel.



About

In TutLogic, we want to share our knowledge with all of the Internet community and welcome your feedback as well. Whether you want to learn with videos or textual articles, it is all available for everyone at tutlogic.com and at our YouTube Channel.