index > Visual Basic for Applications (VBA) > How do I execute code when I open a workbook?

How do I execute code when I open a workbook?


I need to know how to start a VBA script when I first open a workbook without having to do anything else to activate it. Any help on this would be greatly appreciated.
Derek at Potters Clay

Hi,

put the code in the Workbook_Open event. Select 'ThisWorkbook' in the project explorer and paste the following, any code you put in there will run when the book is opened.

Private Sub Workbook_Open()

End Sub




www.dsmyth.net/blog
Derek Smyth

Are you after the special facility hiding thus:

In the VBA editor, with View / Project Explorer operational, find ThisWorkbook under M S Excel objects and double-click it. Change the left dropdown above the code screen to workbook and it will give you the outline of a macro which will auto run on opening. And here I was online trying to solve a problem caused by that very facet of VBA

StephenA 4A
reply 3

You can use google to search for other answers

 

More Articles

• compiler for VBA application?
• Getting Images embedded in Word
• How To Transfer Data to ADO Data Source from Excel with ADO
• format field
• Distributing a Macro across an organization - how to delete exist...
• provider cannot found with MDAC 2.8 Win XP sp2
• Select query returns non-existing data
• VBA hangs when closing Access, PPT, Outlook, Excel
• Assign Minimum and maximum values for a MSGraph
• Removing Hyperlinks
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• Error with Data refreshing in the backgr
• Upgrading from Excel 2000 to 2003
• VBA SDK mfc sample
• Array lengths
• pl help ,how to give warnings or Error M
• Creating AD user with profile & home
• Focusing on textbox (in PPT)(use VB?)
• Accessing OLE object properties (powerpo
• Sorting 3 columns in Excel using VBA.
• how to close a userform in workbooks.ope
• Runtime error '-2147467259(80004005)';
• Left and Right Margins in special cases
• Help with highlighting employees nominat
• OUTLOOK: "Edit with Microsoft Word&
• Calling c# assembly - Works from Excel 2

Hot Articles

• excel rowheight
• Visio VBA Macro to detect connector endp
• Missing files
• Memory issue with variable declaration i
• ScreenUpdating
• VBA Editor fails to start from Access 2003
• Newbie Help: All caps to Title caps
• Macro to sort an Excel column
• Using the API of Visio to open a Custom
• Trying to get just the file name
• VBA XmlMap.loadXML problem - repeating c
• Can you tell me why Int(1.4 * 100) = 139
• Named range in another open workbook
• Sending Mail as a different user in outl
• graphic on/off

Recommend Articles

• VBA Mail Merge Question
• passing data from a form to a module
• VB in word 2000 / form built into a temp
• vba access updating a record
• Disable events in userform
• jump to other slides of a ppt by selecti
• VBA Module to DLL
• worksheet_change and data validation
• Shared Addin using Word
• VBA Shell Function / Windows API Create
• Error hanlder that does not end macro
• Office 97 / Windows 2000 Compatability
• PPT VBA - Automatic undo
• Need help with VBA project, need it to t
• Source Object as a query