Count number of times macro was executed

B

Boss

Hi,

Can we record the number of times the macro is getting executed?

Can this be recorded in a cell? Better if this can be recorded in a variable
within the VBA code.

By doing this i would actually limit the use of macro to senior people in
the organisation i work for.

Thanks in advance.
Boss
 
M

Mike H

Hi,

This writes the number of times the macro has been executed to a text file.
Make these the first lines of your sub

Sub ControlFreak()
Filenum = FreeFile
fname = "C:\timesrun.text"
If Dir(fname) <> "" Then
Open fname For Input As Filenum
Input #Filenum, timesrun
timesrun = timesrun + 1&
Close #Filenum
Else
timesrun = 1&
End If
Open "C:\timesrun.text" For Output As Filenum
Print #Filenum, timesrun
Close #Filenum
MsgBox "This macro has been run " & timesrun & " Times"
End Sub

Mike
 

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