VBS macro doesn´t run

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to close the CMD after running my vbs file, can someone help me?

Code:

Rich (BB code):
Dim objExcel, ObjWB

WScript.Sleep (200)
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

Set ObjWB = ObjExcel.Workbooks.Open("D:\Users\AFCALME\Documents\Projeto_Luis\Andre\EEC\QEIM\QEIM_geral\Teste_Def.xlsm", , True)

ObjWB.Saved = True
ObjWB.Close
objExcel.DisplayAlerts = False


Set objWorkbook = Nothing
Set objExcel = Nothing
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
How are you running the .vbs file?

One way from VBA, which should close the command window after the script has run is:
VBA Code:
    Shell "wscript " & Chr(34) & "C:\path\to\the VBScript file.vbs" & Chr(34), vbNormalFocus
If specifying cmd, use the /c switch to close the command window after the script has run, or /k to keep it open (useful for debugging to see the output, and type exit to close the window):
VBA Code:
    Shell "cmd /c wscript " & Chr(34) & "C:\path\to\the VBScript file.vbs" & Chr(34), vbNormalFocus
    Shell "cmd /k wscript " & Chr(34) & "C:\path\to\the VBScript file.vbs" & Chr(34), vbNormalFocus
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

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