Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

VBA Code: How to auto trigger operation on opening or closing an excel file

Problem : We need to perform or auto-trigger some operation while opening or closing an excel file. There may be operations required by excel user like connecting to database and auto populating the data from database  on opening the excel file and generating pivot tables and charts automatically based on database data. Similarly it can be any other event that user want to perform on opening excel file(saved in macro-enabled xlsm file format)


How to create a module in excel VBA?


Open the VBA editor by clicking Alt + F11 or go to Developer tab and click on Visual basic. Below image shows how to create a sub or function in VBA. Following are the steps for creating a sub or function in VBA:

1. Click on Developer

2. Click on Visual basic icon. (The above two steps can be achieved by clicking on Alt + F11.

3. In the workbook, add new module.

4. In the module, add sub as shown below.


Adding a sub in visual basic



How to create a sub that will be auto-triggered on opening the excel file?


Create a sub with name as auto_open as shown in the code below. Try writing a small code as shown below which will display a message box when the excel file opens.


 Sub auto_open()  
   MsgBox "Show message while opening the excel file"  
 End Sub  

How to create a sub that will be auto-triggered on closing the excel file?


Create a sub with name as auto_close as shown in the code below. Try writing a small code as shown below which will display a message box when the excel file closes.

 Sub auto_close()  
   MsgBox "Show message while closing the excel file"  
 End Sub  

Save the excel file in .xlsm format. 


Mindmap for Test Strategy

A test strategy acts as an outline document that describes the testing approach in the software development cycle. It is created to inform different stakeholders including project managers, testers, and developers about some key issues in the testing process.

A test strategy can be defined at organisation level or project level. If described at organisation level, the strategy is implemented in the projects in the organisation. Test Strategy document is not updated often and defines standards for testing activities and processes.

Mind Maps: Add-ins in Unified functional testing

Mind Maps: Add-ins in Unified functional testing

In this article mindmap for Add-ins in UFT is explained:


1. Web Add-in Extensibility extends Web  Add-in to customize how UFT recognizes  and interacts with different types of controls

2. We can add or remove add-ins associated  with test in UFT

3. UFT license enables the use of all UFT add-ins.

4. Add-ins in UFT are broadly classified as web  based and windows based application support

5. UFT add-ins help you to create and run tests  and business components on applications  in a variety of development environments.

6. We can define run and record setting for each  of the environment once the add-in is loaded