where put code for automatic execution upon opening workbook?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Thanks for any help.
I have a workbook with a couple worksheets, and upon opening, I want the
active cell to always be A1 for each worksheet, and the active worksheet to
be the first one. The way I do that now is, after I do modifications, I click
A1 and save with the first workbook activated. But this is a hassle to do
everytime. I forgot where to put code that always executes when the workbook
is open. Where do I put it, or how do I label it?
Thanks very much.
 
Hi Ian,

Try pasting the following code into the workbook's This Workbook module.

Sub workbook_Open()
Dim sh As Worksheet
Dim i As Long

Application.ScreenUpdating = False
For i = Me.Worksheets.Count To 1 Step -1

Worksheets(i).Activate
Range("A1").Select
Next
Application.ScreenUpdating = True

End Sub

To get to the ThisWorkbook module, right-click the Excel icon right-click
the Excel icon on the worksheet (or to the left of the File menu if the
workbook is maximised), select View Code from the menu, and paste the code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top