VBA code that start with Windows Scheduler is repeatedly running

anichols

New Member
Joined
Mar 11, 2021
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hello everybody,

I have what I assumed was a pretty simple code, but for some reason it keeps rerunning, so perhaps there is an error in my code, or maybe just a smarter way to go about doing this.
Here is the This workbook code:
VBA Code:
Private Sub Workbook_Open()
Application.Visible = False
Start.Show
End Sub
The userform start only has 1 piece of code behind it:
VBA Code:
Sub UserForm_Initialize()
  Application.ScreenUpdating = False
  Me.StartUpPosition = 0
  Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * Me.Width)
  Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * Me.Height)
Start.Label1.Caption = "I am creating your daily folders right now."
Start.Label2.Caption = "Folders will be created for the following Directories:"
Me.Repaint
Application.OnTime Earliesttime:=Now + TimeValue("00:00:15"), _
                   Procedure:="Module1.folders", _
                   Schedule:=True
'The times listed are running total not individual...
Application.OnTime Earliesttime:=Now + TimeValue("00:00:30"), _
                   Procedure:="Module1.closeit", _
                   Schedule:=True
End Sub
Module 1 only has 2 subs in it:
VBA Code:
Sub folders()
Sheets("FOLDERS").Select
MkDir [D4&E4]
MkDir [D5&E5]
MkDir [D6&E6]
'MsgBox "Folders Made Successfully"
Sheets(1).Select
Start.Label1.Caption = "Ok, Drew, I'm all done for today! It has been a pleasure to serve you!"
Start.Label2.Caption = "Folders were created for the following Directories:"
Start.BackColor = &HC00000
Start.Repaint
End Sub
Sub closeit()
Start.BackColor = &H8080&
Sheets(1).Select
Application.ScreenUpdating = True
ActiveWorkbook.Save
Application.Visible = True
ActiveWorkbook.Close
End Sub

All I'm doing is creating a few folders based on cell values (which it creates the first time, then pops errors and still tries to run)
This program is open by windows task scheduler at 9am everyday. There is a delay in the process for the userform to be visible for 15 at start and finish of the program.

any assistance would be greatly appreciated.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

anichols

New Member
Joined
Mar 11, 2021
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Any thoughts out there? I continue to review this, but cannot figure out why it acts up.
 

vw412

Active Member
Joined
Dec 16, 2011
Messages
323
Office Version
  1. 2019
  2. 2016
  3. 2010
  4. 2007
Platform
  1. Windows
I am not sure what is happening but might suggest that instead of ActiveWorkbook.Close in CloseIt routine you might use Application.Quit to actually close Excel since the workbook is saved.
 
Solution

anichols

New Member
Joined
Mar 11, 2021
Messages
40
Office Version
  1. 365
Platform
  1. Windows
You know, I tried it, and it seems to have fixed the issue. I can't believe it. That also solved a few other irritations with other projects, so thank you very much!
 

Watch MrExcel Video

Forum statistics

Threads
1,130,417
Messages
5,642,003
Members
417,250
Latest member
spr1nger

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
Top