Reg: Macro - Auto run [Solved/Closed]

Report
-
 jee -
Hello,
I need to run a macro automatically when i open an excel sheet.
and aslo to run a macro when i close the sheet
can any one help me in this.

regards
jee

5 replies

Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
790
I tried in my excel 2002 it works.

let us what could be the problem

go to some other sheet and then select sheet
does this help
If it does not
goto vbeditor (alt+F11)
then in the vbe editor click view and click immediate window
in the immedite window pate
application.enableevents=true
and hit enteer key at the end of the above line.
now again go someother sheet and again come back to sheet 1

The logic is whever you select sheet 1 the macro m will operate. by merely staying in sheet 1 it will not operate. keep this in mind. \\
confirm whether it is ok or still some problem.
1
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 3288 users have said thank you to us this month

Hi
ya its working once we select some other and return back to Sheet 1 ..
Thanks a lot venkat ..
its possible to run macro without doing this..
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
790
This is an event code. some event should happen. in this case it is activating a sheet. it can be double click or right click a cell or change in selection of a cell or change in the value of a cell which event do you want the fire the macro?????
the events are:
* Activate
* BeforeDoubleClick
* BeforeRightClick
* Calculate
* Change
* Deactivate
* SelectionChange
1
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 3288 users have said thank you to us this month

Fine.Thanks a lot venkat.
now i can trigger a macro by some events.thanks for the information .
take care.
Posts
7073
Registration date
Saturday April 7, 2007
Status
Moderator
Last seen
June 24, 2020
498
Hello,

To automatically run a macro when you open a workbook, you have to add in a module of your workbook (with your example here) :
Sub Auto_Open()
        Activesheet.cells(5,5).value = 67 
End Sub


Best regards
1
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 3288 users have said thank you to us this month

Thanks
Venkat...
Take care.
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
790
is it when you open the sheet or open the workbook

I assume when you activate a sheet.


right click the sheet tab and paste these two event codes

Private Sub Worksheet_Activate()
macro name
End Sub


Private Sub Worksheet_Deactivate()
macro name 
End Sub
Hi
venkat its not working..
i did the same..

from jee
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
790
not clear where was the problem.. was the original macro in standard module
did you introduce the macro name in the space between the lines


Private Sub Worksheet_Activate()

and

end sub

what is your macro. post the macro

and the module number in which the macro is parked.
Hi venkat
I did the same .still its not working
my macro is in module1.
just a simple macro(sample)
Sub m()
Activesheet.cells(5,5).value = 67
end sub

i insert the code in sheet1

Private Sub Worksheet_Activate()

m

end sub

but its not working