ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Schedule an xl file (https://www.excelbanter.com/excel-worksheet-functions/32994-schedule-xl-file.html)

Zubair

Schedule an xl file
 
Greetings.......
How can i schedule to run an xls file on specific time if it has macros to
enable.

Thanks in Advance
Zubair

arno

Hi Zubair,

How can i schedule to run an xls file on specific time if it has
macros to enable.


Create a scheduled task in Windows to run a batchfile, the batchfile
can start Excel and your xls-file, the xls-file needs an auto_open
macro (or the workbook event for the same purpose) to start the
procedure.

arno


Zubair

Thanks for quick response......
Could you please elaborate more , I dont have a real coding but it is an
SQL.REQUEST that fetches record from a database.

Thanks
Zubair


"arno" wrote:

Hi Zubair,

How can i schedule to run an xls file on specific time if it has
macros to enable.


Create a scheduled task in Windows to run a batchfile, the batchfile
can start Excel and your xls-file, the xls-file needs an auto_open
macro (or the workbook event for the same purpose) to start the
procedure.

arno



arno

Hi Zubair,

an SQL.REQUEST that fetches record from a database.


if this is working, fine. if it is not, then pls. try starting a new
thread to solve the problem.

So, if your sql. is working then create a macro called

auto_open.

It should look like this

sub auto_open()
application.run("yourmacrofetchingthedata") ' start your sql-request
thisworkbook.saved = true 'do not ask when closing the book w/o saving
application.quit 'close excel
end sub

When you open the workbook (let's call it yourfile.xls) the macro will
run and close excel. Now you need a batchfile "mybatch.bat" to run that
file with the following line:

"c:\...path...\excel.exe" "c:\...whateverpath...\yourfile.xls"

Doubleclicking on mybatch.bat will start excel, open yourfile.xls,
execute your macro and close excel.

Then you need a scheduled task from windows, in you explorer click on
start/settings/controlpanel/scheduledtasks and create a new one. In the
"task" window you can specify mybatch.bat to run, which username should
be used etc., in the next window you can set the time/days when it
should run. Pls. note, that your PC has to be turned on if you want the
macro to run overnight. If you run it on a server make sure you have
sufficient privileges to do so or you need an (admin) username and
password.

Have a try,

arno



All times are GMT +1. The time now is 05:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com