Questions tagged [vbscript]

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic. VBScript is not the same thing as VBA or VB.NET. They are three different things, so use the correct tags.

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic.

VBScript is commonly used for automating administrative and other tasks in the Windows operating systems (via Windows Script Host --) and for server-side scripting in web applications. It can also used for client-side scripting in (not other browsers), but is generally used for this purpose only in intranet web applications, where the browser can be limited to IE. VBScript is also the language used to create custom Outlook forms ().

Although VBScript has much common syntax with VBA, do not tag questions as unless you are specifically asking about both. It is also completely different than VB.NET.

Some differences between VBScript and VBA:

  • Does not support enumerated constants; replace with the numeric value:

    'VBScript
    Outlook.CreateItem(0)
    
    'VBA allows this:
    Outlook.CreateItem(olMailItem)
    
  • All variables are of type Variant, and are declared without a type specification:

    'VBScript
    Dim olApp  
    Dim msg
    
    'VBA allows this:
    Dim olApp As Outlook.Application  
    Dim msg As Outlook.MailItem
    
  • Method calls don't support named arguments.

    'VBScript
    wb.SaveAs "output.csv", 6, , , , False
    
    'VBA allows this:
    wb.SaveAs FileName:="output.csv", FileFormat:=xlCSV, CreateBackup:=False
    

Executing VBScripts with WSH -- WScript/CScript

VBScript can be executed locally either in GUI mode, in which output is displayed as a window:

wscript.exe C:\Script\Location\script.vbs

or in console mode, in which input is read from and written to a console window.

cscript.exe C:\Script\Location\script.vbs

Running wscript.exe or cscript.exe without specifying the path will run the script in the machine's architecture -- 32-bit on 32-bit machines, and 64-bit on 64-bit machines. On 64-bit machines, it is possible to have the script run in the 32-bit emulation layer:

C:\windows\SysWOW64\wscript.exe  C:\Script\Location\script.vbs
C:\windows\SysWOW64\cscript.exe  C:\Script\Location\script.vbs

Note: Scheduled VBScript tasks must be run with cscript.exe because computer/domain policies limit activation of GUI applications when no user is logged on.

Debugging scripts

Visual Studio (Community Edition, or the Integrated Shell of pre-2013 versions) can be used to step through scripts and locate errors.

  • //X will trigger the debugger if there is a runtime error, or a code breakpoint
  • //D will trigger the debugger at the beginning of the script

No variable expansion
Like other languages in the Visual Basic family, VBScript does not expand variables inside string literals, so in code like

var1 = "fox"
var2 = "The quick brown var1 jumps over the lazy dog."

the value of var2 will remain The quick brown var1 jumps over the lazy dog. instead of becoming The quick brown fox jumps over the lazy dog. To get the value of a variable in a string, the variable must be concatenated with the rest of the string:

var1 = "fox"
var2 = "The quick brown " & var1 & " jumps over the lazy dog."

Frequently Asked Questions

Resources

Related Tags

18718 questions
3
votes
1 answer

Edit text and save

I'm making a script in hta and needed him to have the following functions: It has the following functions: Do not open the script if the file .txt does not exist. Remove the the inputbox and still be able to save the changes. If the User try to…
Humberto Freitas
  • 461
  • 1
  • 6
  • 21
3
votes
3 answers

VBScript custom textbox

I currently have a script that takes a PC name and then outputs the IP Address and then another textbox with the Fully Qualified Domain Name. I have been using the InputBox instead of Msgbox as I need to be able to copy the results to the clipboard.…
Walthavian
  • 33
  • 1
  • 5
3
votes
2 answers

Windows script host - There is no file extension in (file path)

I am trying to run a windows script using windows task scheduler. I am getting the following error. This is the full file path C:\Users\Desktop\service calibration details\RunExcel\RunExcel.vbs The above screen shot does not show the full…
adrian
  • 284
  • 2
  • 4
  • 14
3
votes
1 answer

how to run Qtp from Jenkins

I am new to QTP. I want to trigger QTP from Jenkins.I have automated a website using QTP and have then obtained the vbscript by following file->settings.Now I want jenkins to trigger the vbscripts such that I am able to view the automation process.I…
RCBian
  • 1,080
  • 2
  • 20
  • 31
3
votes
1 answer

XML nodes with root not working in VBScript

The below code works fine with XML 1 but doesn't read rows from XML 2 (ROOT added). Do you know why? Set xmlDoc = CreateObject("Msxml2.DOMDocument") xmlDoc.async="false" xmlDoc.setProperty "SelectionLanguage", "XPath" xmlDoc.load("test.xml") set …
Przemek
  • 317
  • 2
  • 10
3
votes
2 answers

Get title opening windows and close with specific title?

How can I close a window with a specific title in Windows XP base using VBscript? Or is there another way to solve this problem?
Alexandr
  • 117
  • 1
  • 2
  • 7
3
votes
1 answer

Use vbs to open an excel workbook, run a macro and save the workbook

I have a macro that I need to be run every 5 min. I have a vbs file that schedules the macro. The macro is checking for new files in some folder, writes their info into a table, and moving the files into archive. The table is in the same excel file…
ALEXM
  • 87
  • 1
  • 2
  • 11
3
votes
6 answers

How to download a file without browser and open/save dialog batch maybe?

I'm asking that what other method to download a file from internet other than browsers and other softwares, i think is possible with CMD(command line), batch script ? To be more exactly to use a windows (let say 7) component to download a file…
3
votes
3 answers

How to exit more than 1 for loop in Excel VBA?

The code is like: 'first for loop for I = 1 to 5 do sth 'second for loop for j = 2 to 7 do sth 'third for loop for m = 2 to 43 if [condition] then exit 2nd and 3rd loop and continue on…
Meng
  • 1,148
  • 5
  • 15
  • 23
3
votes
3 answers

Replace special characters in vbscript

I have a set of strings that may or may not have special characters in it. Example: Windows Live Fot¢t r Galer¡a fotogr fica de Windows Live Windows Live Maker What i wanna do is to: check whether the whole string contains a special character in…
user352156
  • 99
  • 1
  • 4
  • 14
3
votes
3 answers

What's wrong with this regular expression (VBScript/JavaScript flavor)?

I'm trying to run a regular expression in VBA code that uses Microsoft VBScript Regular Expressions 5.5 (should be the same as JavaScript regular expression). Regular expression: ^[0-9A-Z]?[0-9A-Z]{3}[A-Z]?([0-9A-Z]{6})-?([0-9])?$ Input:…
Michael Paulukonis
  • 9,020
  • 5
  • 48
  • 68
3
votes
5 answers

Display multiple markers on a map with their own info windows

I need to display multiple markers on a map, each with their own infowindow. I have created the individual markers without a problem, but don't know how to create the infowindows for each. I am generating a map using the V3 API within an ASP-based…
3
votes
1 answer

Call Slack API via VBScript Rule in Outlook

I'm trying to run a rule in Outlook that runs a VBScript which calls a Slack.com webservice and updates one of my Slack Channels with a specific message. Current state -- i just want it to post a static message. Future state i'm going to try to…
Birkley
  • 183
  • 1
  • 13
3
votes
3 answers

How to get variables from another vbscript (another .vbs file)

I have a file which has following variables. Dim apple(10) apple(0)= "banana" apple(1)= "2 banana" apple(2)= "3 banana" and these variables are in script/test/test.vbs Now i have another file which has following MSGBOX apple(0) MSGBOX…
3
votes
1 answer

How to loop a loop in VBScript?

I am trying to know how to, or even know if it is possible to, loop inside a loop in VBScript. Here is what logically world work: Do until y=5 msgbox "msgbox 1 loop test" Do Until z=5 msgbox "msgbox 2 loop test" z=z+1 loop y=y+1 loop That code…
user4119689
1 2 3
99
100