programming4us
 
Office
 

Microsoft Excel 2010 : Automating Repetitive Tasks by Using Macros - Running Macros When a Workbook Is Opened

4/12/2014 9:15:14 PM

One advantage of writing Excel macros in VBA is that you can have Excel run a macro whenever a workbook is opened. For example, if you use a worksheet for presentations, you can create macros that render the contents of selected cells in bold type, italic, or different typefaces to set the data apart from data in neighboring cells. If you close a workbook without removing that formatting, however, the contents of your workbook will still have that formatting applied when you open it. Although this is not a catastrophe, returning the workbook to its original formatting might take a few seconds to accomplish.

Instead of running a macro manually, or even from a toolbar button or a menu, you can have Excel run a macro whenever a workbook is opened. The trick of making that happen is in the name you give the macro. Whenever Excel finds a macro with the name Auto_Open, it runs the macro when the workbook to which it is attached is opened.

Tip

If you have your macro security set to the Disable With Notification level, clicking the Options button that appears on the Message Bar, selecting the Enable This Content option, and then clicking OK allows the Auto_Open macro to run.

In this exercise, you’ll create and test a macro that runs whenever someone opens the workbook to which it is attached.

Set Up

Open the RunOnOpen_start workbook, click the Enable Content button on the Message Bar (if necessary), and save the workbook as RunOnOpen. Then follow the steps.

  1. On the View tab, in the Macros group, click the Macros arrow and then, in the list that appears, click Record Macro.

    Set Up

    The Record Macro dialog box opens.

  2. In the Macro name box, delete the existing name, and then type Auto_Open.

    Set Up
  3. Click OK.

    The Record Macro dialog box closes.

  4. Select the cell range B3:C11.

  5. On the Home tab, in the Font group, click the Bold button twice.

    Set Up

    The first click of the Bold button formats all the selected cells in bold; the second click removes the bold formatting from all the selected cells.

  6. Click cell C11 and then, in the Macros list, click Stop Recording.

    Excel stops recording your macro.

  7. In the Macros list, click View Macros.

    The Macro dialog box opens.

    Set Up
  8. Click Highlight, and then click Run.

    The contents of cells C4, C6, and C10 appear in bold type.

  9. On the Quick Access Toolbar, click the Save button to save your work.

    Set Up
  10. Click the Close button to close the RunOnOpen workbook.

    Set Up
  11. Click the File tab and then, in the Recent Documents list, click RunOnOpen.xlsm. If a warning appears, click Enable Content, and then click OK to enable macros. RunOnOpen opens, and the contents of cells C4, C6, and C10 change immediately to regular type.

    Set Up
  12. On the Quick Access Toolbar, click the Save button to save your work.

 
Others
 
- Microsoft Excel 2010 : Automating Repetitive Tasks by Using Macros - Running Macros When a Button Is Clicked
- Microsoft Excel 2010 : Automating Repetitive Tasks by Using Macros - Creating and Modifying Macros
- Microsoft Excel 2010 : Enabling and Examining Macros (part 2) - Examining Macros
- Microsoft Excel 2010 : Enabling and Examining Macros (part 1) - Macro Security in Excel 2010
- Microsoft Project 2010 : Maintaining Baselines (part 3) - Resetting a Baseline , Multiple Baselines
- Microsoft Project 2010 : Maintaining Baselines (part 2) - Rolling-Wave Planning with Baselines
- Microsoft Project 2010 : Maintaining Baselines (part 1) - Clearing a Baseline
- Microsoft Project 2010 : Viewing Baselines (part 2) - Formatting the Gantt Chart to Display the Baseline
- Microsoft Project 2010 : Viewing Baselines (part 1) - Tracking Gantt View and the Variance Table
- Microsoft Project 2010 : Understanding and Setting Baselines
 
 
REVIEW
 
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- Sigma 24mm f/1.4 DG HSM Art

- Canon EF11-24mm f/4L USM

- Creative Sound Blaster Roar 2

- Alienware 17 - Dell's Alienware laptops

- Smartwatch : Wellograph

- Xiaomi Redmi 2
 
VIDEO TUTORIAL
 
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
 
Top 10
 
- Setup Free Media Server To Stream Videos To DLNA Compatible TV, Xbox 360 & PS3 (Play Station 3)
- How To Install Android Market & Google Apps On Kindle Fire
- How To Make Ubuntu Look Like Windows 7
- How To Add A New Account in MS Outlook 2013
- Get Android & Mac OS X Style Gadgets For Windows 7 & Windows 8 With XWidget
- How To Activate Microsoft Office 2013
- How To Install Actual Facebook App On Kindle Fire
- How To Create, View And Edit Microsoft Office Files On Kindle Fire
- Download Attractive Business PowerPoint Templates For Free At SlideHunter
- How To Use And Enable Hibernate & Sleep Mode In Windows 8