ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   where put code for automatic execution upon opening workbook? (https://www.excelbanter.com/excel-programming/332150-where-put-code-automatic-execution-upon-opening-workbook.html)

Ian Elliott

where put code for automatic execution upon opening workbook?
 
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.

Norman Jones

where put code for automatic execution upon opening workbook?
 
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

---
Regards,
Norman



"Ian Elliott" wrote in message
...
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.





All times are GMT +1. The time now is 02:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com