Run a macro only once from a template...

shajueasow

Well-known Member
Joined
Oct 7, 2004
Messages
1,926
Hi,
I have a template with some macros in it. Is it posibble to run an other macro, when template is opened as .xls for the first time. I just want to rename the sheets with dates of the month in which the file is opened. Is it possible?
TIA
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
yes. you can see this in thisworkbook module.

Code:
Private Sub Workbook_Open()
   'your codes here
End Sub
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
You need to flag somehow if the sheet names has been updated or not.

eg.

If Sheet1.Name = "Sheet1" Then
'''' your code to change sheet names
End If

So that it will run only once
 

shajueasow

Well-known Member
Joined
Oct 7, 2004
Messages
1,926
Thanks for both.
But agihcam, your method will always run the macro when the workbook is opened. But I need to run it only once, that is if the sheets are renamed then it shoud not run.
And jindon, that is a nice way that you have suggested. Thank You.
And thanks to agihcam too for sharing his idea.
 

Forum statistics

Threads
1,136,621
Messages
5,676,852
Members
419,656
Latest member
lironprofit

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top