macro run

T

tomi12619

Hi

How is it possible to start a macro immidiately after the Excel file is opened?
My other question is: how is it possible to run a macro when I step into a specified cell?

Thank you in advance.
Thomas
 
C

Chip Pearson

How is it possible to start a macro immidiately after the Excel file is
opened?

Name the macro Auto_Open or use the Workbook_Open event procedure in the
ThisWorkbook code module. The difference between these methods is that
Auto_Open will not run if the workbook is opened via VBA code, while
Workbook_Open will run regardless of how the workbook is opened (assuming
EnableEvents is True).
My other question is: how is it possible to run a macro when I step into a
specified cell?
Use SelectionChange event. In the code module of the worksheet containing
the cell, use code like the following. This will run the 'your code here'
code if the user selects cell A10.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then
Exit Sub
End If
On Error GoTo ErrH:
If Target.Address = "$A$10" Then
Application.EnableEvents = False
'''''''''''''''''''''''
' your code here
'''''''''''''''''''''''
End If
ErrH:
Application.EnableEvents = True
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)



Hi

How is it possible to start a macro immidiately after the Excel file is
opened?
My other question is: how is it possible to run a macro when I step into a
specified cell?

Thank you in advance.
Thomas
 

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

Top