Run Auto Macro only once

J

Jim D

I need to run an Auto Macro only the first time a file is opened. On
subsequesnt opening of the file, no action should occur. Any help is
appreciated.
 
D

Don Guillett

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Res As Variant
On Error Resume Next
Res = ThisWorkbook.Names("RunOnce").Value
If IsEmpty(Res) Then
MsgBox "Run Once Code"
End If
ThisWorkbook.Names.Add "RunOnce", "TRUE"


End Sub


You can reset it by deleting the name "RunOnce"
 
S

Sandy Mann

Have the Macro look for some value in a cell, (which may be a hidden cell if
you wish), and quit if it finds it. Later in the Macro have the Macro place
the value that it will look for the next time that it runs. The Macro will
therfore only run the first time or if you delete the value in the cell.


--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings

[email protected]
[email protected] with @tiscali.co.uk
 
Top