Be the first user to complete this post

  • 0
Add to List

Introduction to Excel WorkBook

One complete Excel file is called as WorkBook.

Now this is something interesting, for dealing with the WorkBook, in general we have two options

  1. By using ActiveWorkbook
  2. By Storing the instance of ActiveWorkbook to WorkBook reference

By using ActiveWorkbook


By Storing the instance of ActiveWorkbook to WorkBook reference

Dim mainWorkBook as WorkBook

Set mainWorkBook = ActiveWorkbook


this is basic example, you will see the detail explanation about WorkBooks, WorkSheets and Range in next sections.

Why we prefer the option 2:

Suppose you have many excel files opened already and your MACRO is using ActiveWorkbook option dealing with more than one excel files at a time then your ActiveWorkbook will keep on changing as it deals with different excels and this may confuse the program and you might end up with Errors. On the other hand if you store the instance of a ActiveWorkbook to a reference then all you have to do is just get hold with that reference and it will always refer to the main workbook where your code is written.

Also Read:

  1. VBA-Excel: Working with Microsoft Word
  2. VBA-Excel: Add Worksheets For All The Given Dates Except Weekends and Copy The Common Template In Each Worksheet
  3. VBA-Excel - Merger - Merge or Combine Many Word Documents Into One
  4. VBA-Excel: Create a new Word Document
  5. How to Enable Macro in Excel
  6. VBA-Excel: Convert Numbers (Rupees) into Words OR Text - Updated Till 1000000 Crore With Decimal Numbers
  7. Excel-VBA : Prevent Adding New Worksheet
  8. Excel-VBA : Send a Simple Mail From MS Outlook Using Excel