RE: only run macro for certain users....

philhowell

Board Regular
Joined
Jun 11, 2002
Messages
175
RE: only run macro for certain users....

hi,

i have a VBA macro that i only wish to run between 12pm an 1am and for a specified user name (stored in options > General) .......

any suggestions
Cheers
Phil[/i]
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi,

you could get excel to enter the date and time into a box - establish whether or not it is after 12pm and before 1am - if so the macro would procede.

Then it could use the Environ function to get the username
have an if statement to validate if the username is correct - if so then run, otherwise exit sub.

I think the environ gets the Windows NT login rather than a username - but you could amend the options to be the same.
Hope this helps
Stuart
 
Upvote 0
philhowell said:
hi,
i have a VBA macro that i only wish to run between 12pm an 1am and for a specified user name (stored in options > General) .......

Howdy Phil, you could try something like the following:

<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> TriFactor()
<SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> Time
    <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> <= 0.04
    <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> >= 0.5
    <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Else</SPAN>
        <SPAN style="color:darkblue">Exit</SPAN> <SPAN style="color:darkblue">Sub</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">If</SPAN> Application.UserName = "Phil" <SPAN style="color:darkblue">Then</SPAN>
   MsgBox "All three contingencies met."
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>

Grabbing the windows user name is a different animal involving an api, relatively straight-forward. Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,221,695
Messages
6,161,360
Members
451,699
Latest member
sfairbro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top