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.
Related
I have three xlsm files that I'd like to batch process sequentially (i.e. a.xlms, b.xlms, c.xlms)
They are contained in "c:\xlsm_batch" folder
I've used this batch code to run the files and it WORKS .... BUT DOES NOT save them or close them once they have been run sequentially.
#echo off
for %%x in (C:\xlsm_batch*.xlsm) do (
echo Starting.. %%x
start "" /wait %%x
)
Is there a way to program this into the code (i.e. saving each sequential XLSM file, closing each sequential XLSM file and then opening up a NEW XLSM file for processing?)
Thanks, R
Might be a bit late on this answer but I used a combination of task scheduler, batch files and macro's to open files at month end, update the data, save and close then save a copy in another folder for users to access.
VBA within each file
ActiveWorkbook.RefreshAll
Application.Wait (Now + TimeValue("0:00:20"))
ActiveWorkbook.Save
ActiveWorkbook.Saved = True
Application.Quit
Batch file
#ECHO ON
'Open Original File
Call "C:\FileStoredHere\FileName.xlsm"
'Close all open instances of Excel
taskkill /f /im Excel.exe
'Copy to User Folder
Copy /y C:\FileStoredHere\FileName.xlsm "\\servername\CopyFolder\FIleName.xlsm"
One thing worth noting was I couldn't get mapped drives to work for the copy so use the full UNC file path.
I have the following issue:
- Task: There is a prepared excel that should be opened, and on opening a macro is executed.
- This task should be executed each day at a given time (like at 10:00), execution should happen in the background (so that the user is not disturbed at all).
Problem:
1) If I try to do it with a .vbs file (in task scheduler), then the execution happens in the background, however, some features are lost (there is an excel add-in that establishes connection with a company application, from which it should retrieve some data -> the connection is not set up, no data is received). I guess it lack privileges or something like that.
VBS bode is:
Dim objExcel
Set objExcel=CreateObject("Excel.Application")
objExcel.Application.Run "'C:\SomePath.xlsm'!Module1.Controller"
2) If I try with a .bat file, it works (the connection is ok, data is received), however it flashes and is not running in the background. Simple code:
Start "C:\Program Files (x86)\Microsoft Office\root\Office16\Excel.exe" "C:\SomePath.xlsm"
Does someone have experience with this kind of issues?
I'm open to any other solution. :)
Thank you!
You can run it in the background like this in batch (The main part is the VBScript code):
<!--
#Echo Off
Cscript //Nologo "%~f0?.wsf" //job:VBS
Exit /B
-->
<package>
<job id="VBS">
<script language="vbscript">
Dim WshShell : Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run """C:\Program Files (x86)\Microsoft Office\root\Office16\Excel.exe 'C:\SomePath.xlsm'""", 0, True
</script>
</job>
</package>
Actually i am using nodejs + electronjs for my application and also i am using screensaver for my app.When i start my batch file it executes and shows cmd prompt window on top of my screensaver.So,i want to execute my batch file in background.Can you please give perfect solution for my need?
Try this:
Save as invisible.vbs:
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
Then run your script after calling the vbs script
invisible.vbs <script>
you can use either batch script
#echo off //for remving console text
//Other codes
exit /b 0 //for removing console
pause>nul
I have also faced such type of situation where I had to generate PDF files and allow printer to execute print command for printing pdf files with default printer.for this purpose I have used sumatrapdfreader.I have also developed a package print I think it will be helpful for u.I am sharing link to u.
package link on github
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
>start microsoft-edge:http://google.com
Its opened google.com in edge browser new tab. Now I want to close. Here I am using stop but its not working.
>stop microsoft-edge:http://google.com
If, by chance, the goal is to use Edge to "ping" a website then close Edge, I may have a solution.
The Chromium command line switch --no-startup-window used along with a url in Edge seem to have the effect of closing the application after background-loading the specified page in the background. The bits of documentation I've been able to find about Chromium's command-line switchesI've been able to find for this imply that the application should stay running in the background, but that does not seem to be the case (for me anyway) when used this way.
For example, if you wanted to schedule a recurring background random Bing search, like so you could (hypothetically) auto-collect⁕ Microsoft's Search & Earn points, you may be able to schedule an event to run a batch file every couple hours, something like:
start msedge --no-startup-window https://www.bing.com/search?q=%random%
The only way I could tell it was doing anything at all was by watching the Task Manager for Microsoft Edge to appear for a split second.
⁕This is just an example use case and is probably against the program's terms so don't actually use it for that.
taskkill /F /IM MicrosoftEdge.exe will kill it dead, but this will also terminate any other instances as well. In my experience, this force close will re-open with all tabs that were open before being "killed" even with Edge configured to not open with previous pages. My workaround to that was to taskkill /F /IM MicrosoftEdgeCP.exe repeatedly, with a 1 second delay, until all tabs were closed (going too fast did not kill all tabs). This also killed Edge when the last tab was closed.
Example
start https://www.bing.com/search?q=a
timeout 3
start https://www.bing.com/search?q=ab
timeout 3
start https://www.bing.com/search?q=abc
timeout 3
:KillEdge
timeout 1
taskkill /F /IM MicrosoftEdgeCP.exe
if %errorlevel% NEQ 0 (goto :eof) else (goto KillEdge)
**It work for me **
taskkill /IM msedge.exe /F