Auto run macro when open worksheet

ama150

New Member
Joined
Mar 6, 2002
Messages
8
I want to run a macro when I open a spreadsheet. Can you help?

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
WELCOME TO THE BOARD!

Piece of cake! Open the Visual Basic Editor by pushing ALT + F11. Then click on the folder on the left side called MICROSOFT EXCEL OBJECTS. Now click the ThisWorkbook module. Enter this code on the right:

Private Sub Workbook_Open()
'Enter your macro here
End Sub

Does this hlep?
 
Upvote 0
sure, simply

1. Go to the Visual Basic Editor by pressing the keys Alt+F11.

2. From the Project Explorer, double-click over the ThisWorkbook object

3. That will execute an event window for you. At the top of the new code window, you will see the word 'General'. Select the drop down where you see general and select 'Workbook'.

4. You will notice that Excel VBA assumes the Open event. That means whatever code you insert in this procedure will execute automatically when the workbook is opened.


Private Sub Workbook_Open()
MsgBox "say hello"
End Sub
 
Upvote 0
For me it didn't work, Office 2013
Any clue why?
sure, simply

1. Go to the Visual Basic Editor by pressing the keys Alt+F11.

2. From the Project Explorer, double-click over the ThisWorkbook object

3. That will execute an event window for you. At the top of the new code window, you will see the word 'General'. Select the drop down where you see general and select 'Workbook'.

4. You will notice that Excel VBA assumes the Open event. That means whatever code you insert in this procedure will execute automatically when the workbook is opened.


Private Sub Workbook_Open()
MsgBox "say hello"
End Sub
 
Upvote 0
How do you edit the macro file without running it since you've set it to run when you open it? I have created a macro that will automatically send the files through email but I need to edit it without sending the emails.
 
Upvote 0
You may disable macros in Excel security so they will not run automatically but rather ask for permission. You can access the settings from a different spreadsheet.
 
Upvote 0
How do you edit the macro file without running it since you've set it to run when you open it? I have created a macro that will automatically send the files through email but I need to edit it without sending the emails.

I do this by simply check the file name:

Sub Auto_Open()
CheckNameWorkbook = ActiveWorkbook.Name
FileNameToExecute = "YourFileName.xls"
If CheckNameWorkbook = FileNameToExecute & "m" Then
...Your code here
End If

If I remove the "m" in the file type "xlsm" my macro will not exectue on open. If I then add the "m" again the macro will work as intended upon next open.
 
Upvote 0
Hey !!

I tried doing what is mentioned above, but excel is showing some kind of error, can you look into this and help me ?!

Private Sub Workbook_Open()
Option Explicit
Public dTime As Date


Sub ValueStore()
Dim dTime As Date
Range("I7:I13").Value = Range("C7:C13").Value
Range("J7:J13").Value = Range("G7:G13").Value
Range("K7:K13").Value = Range("H7:H13").Value
Call Hello
End Sub




Sub Hello()
dTime = TimeValue("01:41:00")
Application.OnTime dTime, "ValueStore", Schedule:=True
End Sub


Sub Bye()
On Error Resume Next
Application.OnTime dTime, "ValueStore", Schedule:=False
End Sub
End Sub

This code not working what could be the error ?


sure, simply

1. Go to the Visual Basic Editor by pressing the keys Alt+F11.

2. From the Project Explorer, double-click over the ThisWorkbook object

3. That will execute an event window for you. At the top of the new code window, you will see the word 'General'. Select the drop down where you see general and select 'Workbook'.

4. You will notice that Excel VBA assumes the Open event. That means whatever code you insert in this procedure will execute automatically when the workbook is opened.


Private Sub Workbook_Open()
MsgBox "say hello"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,655
Messages
6,126,053
Members
449,283
Latest member
GeisonGDC

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
Back
Top