Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Count number of times macro was executed

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Count number of times macro was executed

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

"Boss" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Count number of times macro was executed

Thanksyou so much for the code..
It helped me a lot..

Boss

"Mike H" wrote:

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

"Boss" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Number of Times Q Sean Excel Worksheet Functions 5 December 21st 06 05:00 PM
count the number of times the same number shown Noemi Excel Discussion (Misc queries) 1 September 22nd 05 04:00 AM
Count number of times a specific number is displayed in a cell ran subs Excel Worksheet Functions 1 June 27th 05 05:01 PM
Count number of times a specific number is displayed in cells subs[_2_] Excel Programming 1 June 27th 05 03:15 PM
Macro to Count how many times a number occurs on a day SirMetro Excel Programming 8 February 2nd 05 05:36 PM


All times are GMT +1. The time now is 10:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"