ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Run Auto Macro only once (https://www.excelbanter.com/excel-worksheet-functions/143897-run-auto-macro-only-once.html)

Jim D

Run Auto Macro only once
 
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.

Don Guillett

Run Auto Macro only once
 
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"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC



--
Don Guillett
SalesAid Software

"Jim D" wrote in message
...
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.



Sandy Mann

Run Auto Macro only once
 
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


with @tiscali.co.uk


"Jim D" wrote in message
...
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.





All times are GMT +1. The time now is 09:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com