Excel VBA macro to run automatically based on environment user

David Montoya

New Member
Joined
Apr 25, 2018
Messages
49
Dear, I would like to have a macro running automatically on a daily basis (if workbook is opened), on assigned schedule, and based on the environment user name.
I have come up to the following code, but it does not work, and need your assistance to perfected:
Code:
Sub RunSchedule()
If Environ$("username") = "user1" Then
Aplication.OnTime TimeValue("16:40:00"), "macroname"
ElseIf Environ$("username") = "user2" Then
Aplication.OnTime TimeValue("16:45:00"), "macroname"
ElseIf Environ$("username") = "user3" Then
Aplication.OnTime TimeValue("16:50:00"), "macroname"
End If


End Sub

Thanks in advance for your valuable assistance.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
1. You need this procedure in ThisWorkbook module to trigger your macro

Code:
Private Sub Workbook_Open()
    RunSchedule
End Sub

2. Application.OnTime not Aplication.OnTime
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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