Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Introduction to Excel WorkBook

One com­plete Excel file is called as WorkBook.

Now this is some­thing inter­est­ing, for deal­ing with the Work­Book, in gen­eral we have two options

  1. By using ActiveWorkbook
  2. By Stor­ing the instance of Active­Work­book to Work­Book reference

By using ActiveWorkbook

ActiveWorkBook.Sheets(“Sheet1”).Range(“A1”).Value=1

By Stor­ing the instance of Active­Work­book to Work­Book ref­er­ence

Dim main­Work­Book as WorkBook

Set main­Work­Book = ActiveWorkbook

mainWorkBook.Sheets(“Sheet1”).Range(“A1”).Value

this is basic exam­ple, you will see the detail expla­na­tion about Work­Books, Work­Sheets and Range in next sections.

Why we pre­fer the option 2:

Sup­pose you have many excel files opened already and your MACRO is using Active­Work­book option deal­ing with more than one excel files at a time then your Active­Work­book will keep on chang­ing as it deals with dif­fer­ent excels and this may con­fuse the pro­gram and you might end up with Errors. On the other hand if you store the instance of a Active­Work­book to a ref­er­ence then all you have to do is just get hold with that ref­er­ence and it will always refer to the main work­book where your code is written.

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: