This is my first attempt at making a batch file. I am trying to achieve the following: I want to turn on a service, wait 10 seconds, open and excel file, run a macro in the excel file, then close excel file, wait 10 seconds, then turn off a service.
I have managed most of it, please see me bat file below:
net start "DraftSight API Service"
timeout /T 10 /nobreak
"C:\Summary report.xls"
taskkill /IM excel.exe
timeout /T 10 /nobreak
net stop "DraftSight API Service"
I am now at the point that upon executing this batch file that it turns on service, waits, then opens excel but will not run the macro that i have set as Auto_Open (). If i run the macro manually and close excel, the batch file then proceeds to try and close excel, which has already been closed and then executes the reset of the code.
What I want to know is why after opening excel via a batch file, why does it seem to pause the command prompt and how to get around this? Secondly how to run the macro with either the Auto_Open in excel or can I call the macro from the batch file and have it executed?
Thanks for reading and responding
Related
This is my first post, so please be kind.
I have an Excel 2010 VBA macro inside File1.xlsm, which needs to open a second Excel file, File2.xlsx, wait for the second file to be manually edited by the user and closed before it continues. I have no problem opening the second Excel file, but have not been able to figure out how to get the macro to wait until the second file is closed to continue.
Having done some research on this, I tried to adapt suggestions from other similar posts that used Sleep/IsFileOpen in a loop or brought up a message box or user form to temporarily halt processing of the macro. In all of those cases, the second file was opened, but focus was always maintained on the first file that contains the macro. The end result is that I had to close the user form or message box without being able to edit the second file. In the case of the Sleep loop, the Sleep caused all of Excel to Sleep and the application went into an infinite loop checking to see if the file was still open followed by sleeping for 1 second.
Sorry in advance, but the complete listing exists in a closed space and is too complex to re-create here for posting.
I thought this would be simple to start a macro running, have it open a second Excel file, have the user edit/save/close the file and then continue the macro using the updated file. Any suggestions would be appreciated.
I have an XLSM file which contains 2 Web Query connection. When I go to "Connections" in the "Data" tab I am presented with the two connections I have.
For each of these I can edit some properties, one which says "Update every X minutes". I've set this to 1 minute and also ticked "Activate background update".
This, however, won't work as the web query connections aren't run anyway.
Ultimately what I need is to run these connections automatically once every hour. Preferably without any user interaction and without the document being open.
Is this possible?
You can't refresh a connection without the file being open. You can run queries on opening the file or create a VBA routine that opens the file, then uses the RefreshAll and saves over the original file every hour.
You can use VBS too.
The final solution by OP:
I ended up making a little VBS script to handle the open, refresh,
close. Then a batch script wrapper to handle running the VBS script
and logging. Finally Windows Task Scheduler to run the batch script
periodically.
I m trying to open and exit the xlsx file with saving using batch file. If the opens- works ok, but there are some problems with exit- because I cant save new stuff in file using taskkill command.
PROGRAMM=2.xlsx
Start 2.xlsx
Sleep 30
TASKKILL /F /IM EXCEL*
Are there any choices to exit from xlsx with saving using batch?
/f
says to force a termination. Without it it's like clicking the close button, it's a request to the program to terminate, the program is free to ignore it.
With /f the program is not asked to close but is terminated by windows. The program doesn't even know what's happening.
Set xlBook = GetObject("C:\Users\User\Documents\Super.xls")
xlBook.Save
Above vbs script opens and save a document.
While it is possible to run a datanitro script via VBA, this still requires excel to be open. Is it possible to have a .py file that executes datanitro (like opening and closing an excel file) without a human needing to be present to open excel and execute the script?
If it isn't possible yet is it in the works?
DataNitro needs to have Excel open before you can run it, but you can have a script start automatically when a workbook is opened (https://datanitro.com/docs/scripts.html#autostart).
You can combine that with a Python script (outside of DataNitro) or other script to open and close the Excel file and launch the process automatically.
What needs to be done?
I need to make a connection to the remote machine through UNIX, go to the shared drive, open an excel file, save it and close it. This needs to written in an script.
The file contains macros so they needs to be opened manually on daily basis, save it and close it. We plan to write a script that would run on daily basis and refresh this file automatically.
Where am i facing the issue?
Making a connection to the remote machine is done, after that i run certains commands:
1. Open the command prompt
2. cd the file path
3. Open the File
Now this is where the issue starts
How to save the file automatically?
How to close that file?
I tried using the taskill option and it almost worked but it gives out the popup of Do you want to save the file and i dont know how to provide output to that popup through command prompt.
Let me know if you have any idea on how to move ahead on this.
A bit hackish, but xdotool, a program which simulates mouse clicks and keyboard presses could be used. If Windows is being used, then see this question for tools which simulate mouse clicks and keyboard presses.
Have you tried SendKeys?
That may help.