Automatically Opens a Workbook in given date and time

villy

Active Member
Joined
May 15, 2011
Messages
489
Hi everyone,
I'm here again for a new thread that would also be helpful to others, I guess so.
I just want to know how I can instruct excel to open automatically in a given date and time. Not only that but, it will run a vba program then close (note that it should be done unnoticeable by any user-it means a program run through a workbook like nothing happens).

I know someone is really brilliant to know it is so simple.

Thanks in advance.

________________________________
"There's a perfect place and time for everything."
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Something like that.. I know it is possible to give .ontime value to make it automatically open and close the workbook. How?I don't know...

Any idea will be greatly appreciated thanks
 
Upvote 0
Ah, I see now. Something like that:
Code:
[COLOR="Blue"]Sub[/COLOR] Launcher()
[COLOR="Green"]    ' Run Sub at 3PM.[/COLOR]
    Application.OnTime [COLOR="Blue"]Date[/COLOR] + TimeSerial(15, 0, 0)
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]

[COLOR="Blue"]Sub[/COLOR] OpenWorkbook()
    [COLOR="Blue"]Dim[/COLOR] wkb [COLOR="Blue"]As[/COLOR] Workbook
    [COLOR="Blue"]Set[/COLOR] wkb = Workbooks.Open("PATH_TO_WORKBOOK")
[COLOR="green"]    ' Execute Sub in opened workbook.[/COLOR]
    wkb.Application.Run "Module1.CloseWorkbook"
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
I go it but can you make it a little clearer?
where should I put the sub part and where it should be called to?

What "Module1.CloseWorkbook" do?
supposed I have a module name modLog it will be replaced to Module1 right? and why it is .closeworkbook can you explain please..
thanks

 
Upvote 0
I apologize - I forgot to mention Sub to be called.
Code:
[COLOR="Blue"]Sub[/COLOR] Launcher()
[COLOR="Green"]    ' This launches "OpenWorkbook" Sub at 3PM.[/COLOR]
    Application.OnTime [COLOR="Blue"]Date[/COLOR] + TimeSerial(15, 0, 0), "OpenWorkbook"
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]

[COLOR="Blue"]Sub[/COLOR] OpenWorkbook()
    [COLOR="Blue"]Dim[/COLOR] wkb [COLOR="Blue"]As[/COLOR] Workbook
    [COLOR="Blue"]Set[/COLOR] wkb = Workbooks.Open("PATH_TO_WORKBOOK")
[COLOR="green"]    ' This statement calls "CloseWorkbook" Sub in module "Module1" in opened workbook.[/COLOR]
    wkb.Application.Run "Module1.CloseWorkbook"
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
I just remember my workbook has a password, will it work with it? How can I overpass the password dialog or can I set into code to input the password automatically?
Thanks
 
Upvote 0
Code:
[COLOR="Blue"]Set[/COLOR] wkb = Workbooks.Open("PATH_TO_WORKBOOK", [B][COLOR="Red"]Password:="YOUR_PASSWORD"[/COLOR][/B])
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,337
Members
452,907
Latest member
Roland Deschain

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