Selected Answer
Tubrak
Try this at whatever level your code is (changing the macro name to suit and adding whatever code you want to run once).
Option Explicit
Dim FirstRun As Boolean
Sub RunOnce()
Dim Warn As Integer
If FirstRun = False Then
' Your macro code
FirstRun = True
Else
Warn = MsgBox("You can't run this macro more than once, sorry! Please open the file again (now saving file)", vbOKOnly)
ThisWorkbook.Close savechanges:=True
Exit Sub
End If
End Sub
Hope this is what you want. If however you wish to close Excel too, I suggest you do that if your workbook is the only one open (i.e. other workbooks aren't affected). The additions in bold below do that (and note that the Application.Quit command comes BEFORE the .Close):
Option Explicit
Dim FirstRun As Boolean
Sub RunOnce()
Dim Warn As Integer
If FirstRun = False Then
' Your macro code
FirstRun = True
Else
Warn = MsgBox("You can't run this macro more than once, sorry! Please open the file again (now saving file/closing Excel)", vbOKOnly)
If Workbooks.Count = 1 Then Application.Quit 'do this BEFORE closing
ThisWorkbook.Close savechanges:=True
Exit Sub
End If
End Sub