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.
Related
I have an xlsm file containing the code to be run daily at a specific time. Our IT policy blocks the usage of Windows Task Scheduler. Is there a way to open the xlsm file automatically at a specific time? As usual, Thanks a lot to this forum to always come into rescue!!
I have around 20 SQL queries that we run in SSMS every day, copy the grid results, then paste the results in an excel file.
Is there a way (using task scheduler, or excel, or SSMS, or VBA) that I can have those same queries run on their own at 8am, and save to excel or CSV file ?
(I prefer not to have to use Excel's ODBC connection since it will have to run on other desktops possibly.)
Thanks.
Maybe not a 100% exact solution, BUT, there is an add-in SSMSBoost that I develop, it has "Results grid scripting" feature, which exports all grids to excel-compatible "open document spreadsheet" (XML format).
Literally, you run all your 20 queries in 1 batch, get 20 results grids and click 1 button: "Start Scripting" (after pre-configuring the scripter to save every grid to separate file (or it can export each grid to own spreadsheet within 1 file).
Does it help? Yes, you still will have to "run" manually, but SSMSBoost will take care about exporting everything with 1 click.
The feature is described here: https://www.ssmsboost.com/Features/ssms-add-in-results-grid-script-results
There is also a short video about it: https://www.youtube.com/watch?v=waDCukeXeLU
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
I'm invoking a macro within an Excel document via Powershell.
To invoke the macro, I have to run a named macro and call it in run. However, when the macro is invoked and completes successfully, a MessageBox will appear. As far as I know, this messagebox is the only way to find out if the process has completed successfully.
I have no control over the ability to remove the message box. The powershell script must wait for the macro to finish.
From the document: The documentation for this does not give an option for this situation, or so it appears.
Alternative Options I can work with: (But I'm not sure how to get to the point where the messagebox would be dismissed)
The Excel document can have code inserted within it via Powershell
Options can be changed within the document memory space
Is it possible to run a macro asynchronously and to check back on the execution of the macro?
There are a few convoluted ways to go about doing this.
1) Invoke another instance of the Excel application and run the Macro using that. Then how would you know whether it's done? You pass a global variable by reference to it. And use the OnTime functionality to keep checking every few seconds if its done or not.
An example for calling another excel instance is given here: Stop VBA-Script from "freezing" while sending MDX-Query
2) You can store your script as a .VBS file. Then you call the shell to run the VB script and again check some passed-by-reference variable.
3) Use a hidden worksheet as a buffer, which gets written upon in a particular location once the asynchronous code finishes running. Again, you need some clever OnTime programming to automatically run a polling service... and more importantly, to stop running it!
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.