PC Review


Reply
Thread Tools Rate Thread

Count number of times macro was executed

 
 
Boss
Guest
Posts: n/a
 
      18th Sep 2008
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 With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      18th Sep 2008
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 With Quote
 
Boss
Guest
Posts: n/a
 
      18th Sep 2008
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Number of Times Q Sean Microsoft Excel Worksheet Functions 5 21st Dec 2006 05:00 PM
count the number of times the same number shown =?Utf-8?B?Tm9lbWk=?= Microsoft Excel Misc 1 22nd Sep 2005 04:00 AM
Count number of times a specific number is displayed in a cell ran =?Utf-8?B?c3Vicw==?= Microsoft Excel Worksheet Functions 1 27th Jun 2005 05:01 PM
Count number of times a specific number is displayed in cells =?Utf-8?B?c3Vicw==?= Microsoft Excel Programming 1 27th Jun 2005 03:15 PM
Macro to Count how many times a number occurs on a day SirMetro Microsoft Excel Programming 8 2nd Feb 2005 05:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:31 PM.