Vba code to run subroutine in a specific time

ExcelNewbie2020

Active Member
Joined
Dec 3, 2020
Messages
343
Office Version
  1. 365
Platform
  1. Windows
Sir,

Would like to ask for vba code that will auto run my subroutine in a specific time, let say at 5PM.

my subroutine "sendemail" works properly when i hit button (auto send email thru msoutlook) now, instead of a button, i would like to auto run the subroutine everyday at 5PM.

tried to add this line "Application.OnTime TimeValue("17:00:00"), "SendEmail" but did not work...

Note: my excel workbook and msoutlook is running though my pc is locked..
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Have you put the code line in a workbook open event in the ThisWorkbook module?
 
Upvote 0
the code is placed in a seperate module not in thisworkbook module. do you mean, i should transfer the code to thisworkbook module?
 
Upvote 0
The code needs to be in an event procedure so that the macro is triggered to run, most commonly in a Workbook_Open procedure in the ThisWorkbook module
 
Upvote 0
The code needs to be in an event procedure so that the macro is triggered to run, most commonly in a Workbook_Open procedure in the ThisWorkbook module
i think i am missing something.. so what i did now is i add a line in thisworkbook module
Private Sub Workbook_Open()

Application.OnTime TimeValue("10:00:00"), "SendEmail"
End Sub

hoping that at 10AM, this will run "sendemail" subroutine.. I adjust the time to test if it will run on the nearest time.. but it didn't..
 
Upvote 0
Did you close and open the workbook after putting the code in the workbook?
 
Upvote 0
Solution

Forum statistics

Threads
1,223,884
Messages
6,175,174
Members
452,615
Latest member
bogeys2birdies

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