VBS macro doesn´t run

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
103
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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,811
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
 

Macropod

Retired Moderator
Joined
Aug 27, 2007
Messages
3,566
Change:
objExcel.DisplayAlerts = False
to:
objExcel.Quit
 

Watch MrExcel Video

Forum statistics

Threads
1,132,981
Messages
5,656,214
Members
418,290
Latest member
ArrArkRE

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
Top