Activate Workbook Or Worksheet in Excel VBA

Home/Excel VBA/Activate Workbook Or Worksheet in Excel VBA


Sometimes we may want to Activate Workbook Or Worksheet using Excel VBA.You can use Activate property Activate Workbook Or Work Sheet.



50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates

For example, we may have 5 worksheet, we have to do some tasks in Sheet3. In order to perform some tasks we need to activate the worksheet then perform the tasks.

Activate Workbook Or Work Sheet – Example Cases:

Activate Workbook or Worksheet

If you know the name of the workbook You can use the following code to Activate Workbook or worksheet. For example workbook name is “Book2” which we want to activate and it contains sheet named as “Sheet1”. Using following code you can Activate Workbook Or Work Sheet.

Sub Activate_Workbook()
'Activate Workbook
'Activate Worksheet
End Sub

Activate Workbook Or Work Sheet

  1. Open an excel workbook
  2. Press Alt+F11 to open VBA Editor
  3. Insert a new module from Insert menu
  4. Copy the above code and Paste in the code window
  5. Press F5 to see the output
  6. You should see Aactivated workbook and Worksheet
  7. Save the file as macro enabled workbook
Activate Workbook or Worksheet using object

You can create object for workbook and worksheet in the following way.You can use object to activate Workbook or Worksheet.

Sub Activate_Workbook_Using_Object()
'Variable Declaration
Dim WrkBk As Workbook
Dim WrkSht As Worksheet
'Create Object for Workbook
Set WrkBk = Workbooks.Add
'Create Object for Worksheet
Set WrkSht = WrkBk.Sheets("Sheet1")
'Activate Sheet
End Sub
  1. We declared two objects for workbook and worksheet
  2. We have added a new workbook and assigned to workbook object
  3. We set the Worksheet to worksheet object
  4. We activated the worksheet by refering the worksheet object
  5. .

  1. Open an excel workbook
  2. Press Alt+F11 to open VBA Editor
  3. Insert a new module from Insert menu
  4. Copy the above code and Paste in the code window
  5. Press F5 to see the output
  6. You should see output as shown above
  7. Save the file as macro enabled workbook
By |January 12th, 2013|Excel VBA|3 Comments

About the Author:

Excel VBA Developer having around 8 years of experience in using Excel and VBA for automating the daily tasks, reports generation and dashboards preparation. Valli is sharing to helps us automating daily tasks.


  1. Jude September 15, 2014 at 11:20 PM - Reply

    If you worksheet has a space in its name eg: ‘Sheet 1’, how would you reference that?

  2. PNRao September 25, 2014 at 8:25 PM - Reply
    'You can use in same way:
    Workbooks(“Book2.xls”).Sheets("Sheet 1").Activate


  3. Ryan August 16, 2016 at 7:13 AM - Reply

    Hey Valli,

    I have just got a very simple question.

    My current macro pastes into a specific file Windows(“test file.xls”).Activate with this code. I would like to use this macro on various files with different names. Therefore I want it to paste onto my active worksheet, and am unsure of what code it should be .

    Please help!


Leave A Comment

Related pages

excel 2010 unmerge cellsvba loop examplesbcg interview processexcel loop through rowsexport excel macrodata analysis for dummieshow to insert check mark in excel 2007excel unhide workbookexcel userformsample vlookupstock chart in exceladding title to excel chartvba last rowadvanced graphing in excelvba code to copy and pasteexcel macros templatescool excel chartsunmerge cellsit project budget template excelvba macros for beginnersselection vba excelcreate vbahow to apply vlookup formula in exceluse of concatenate in excelclose excel in vbaexcel vba data entry form examplesvb6 interview questionsmicrosoft excel quick keyshow to insert checkbox in excelexcel test for beginnershow to program macros in excelexcel 2010 unprotect cellscase sensitive vlookupexcel sql command textvba tutorial pdfvlookup function in excel examplemsgbox codetcs interview questions and answers pdfshortcut key to insert row in excel 2010vlookup function tutorialxlsx to xml convertersql advanced concepts with examplesexcel 2007 show developer tabmacros in excel for beginnershow to insert many rows in excelunhide cellsexcel vba protect all sheetsdebug vbaunhide all sheets macrohow to unlock an excel fileinteractive excel dashboardschanging rows to columns in excelmacro excel for dummieshow to join cells in excelexcel coding examplesexcel vba application.gotoformula for lookup in excelsort sql statementvlookup excel easy stepsmessage boxes in vbwhat are activex controls in wordmeeting recap formataccess vba close reportvba drop downfilter excel macroapplication worksheetfunction countaactivecell.valueexcel 2010 lookup functionwhat is the iferror function in excelwrite macro in excelhow to hide and unhide columns in excel 2007ddl and dml in sql serverhow to unlock a excel file protected by password