VB Script





VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

Where can I find a good third party tool to write cgi, asp, vb, c sharp scripts?
Free Tool: SSL Checker
LVL 12
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

I am struggling with what should be a very simple fix...or so I thought.

I have an On_Change worksheet event in which every once in a while, the Target Range contains multiple cells.

#1 - I have no idea why this is the case, maybe because the worksheet has a lot of merged cells?
#2 - In these instances, I want to change the range to be a single cell range, because I'm performing calculations on it. But I am struggling to figure out how to do this. I tried this
rng = target
   If rng.Columns.Count > 1 Then
    rng = Cells(rng.Row, rng.Columns(1).Column) ' this is the place where I am having an issue; I am not understanding why this is not resetting my rng object to a single cell
  End If

Open in new window

My Main Code in the On_Change Worksheet Event:

If Not Intersect(Target, Range("AA26:AD41")) Is Nothing Then
 Application.enableevents = False
 Call FormatDefectClock(Target)
 Application.enableevents = True
 End If

Open in new window

My FormatDefectClock Code:

Sub FormatDefectClock(rng As Range)
Dim textclock As String
On Error GoTo oops
  ActiveSheet.Unprotect "111" 
  If rng.Columns.Count > 1 Then
    rng = Cells(rng.Row, rng.Columns(1).Column) ' this is the place where I am having an issue
  End If
  If rng.Value2 = Empty Or rng.Value2 = 0 Then 'if data is cleared
    rng.offset(0, 60).Value2 = 0 ' reset the value
    Call ResetFormat(rng)
  End If
  If rng.NumberFormat = "h:mm;@" And rng.Value2 <> "" And rng.Value2 <> 0 Then ' new data has 

Open in new window

I  am attempting to make a simple program to open some slides and ran into an issue with a vbs script I sourced from somewhere I don't remember.

Dim Wsh
Set Wsh = Wscript.CreateObject("Wscript.Shell")
Wsh.SendKeys "{" + WScript.Arguments.Item(0) +"}"

I used this for a different purpose at the beginning, but wanted to try to use this for commands such as Ctrl+F5.
The way I use the code posted is through a batch command that starts it and gives the argument.
Is there a way I can make this code work with Ctrl+F5 and other combinations as such.
Please disregard.. Didn't know how to remove a question.
I would like to run a script, which will look at a specific folder in a path (ie C:\users\user1\desktop\desktop.zip), and encrypt that zip file with a password.
is this possible, please let me know.
Excel / Macro VB

Have this code it works fine on Excel 2010    (opens runs saves and closes)   upgraded to Excel 2016 and it opens runs and closes but leaves a save dialogue behind which is annoying as it's a scheduled job.  Not sure what I need to add on the newer version of Excel.

Sub Macro1()

' Macro1 Macro
'Refresh Jet
    Application.Run "JetReports.xlam!JetMenu", "Refresh"
    Application.DisplayAlerts = False
    Columns("A:A").ColumnWidth = 4.14
    Rows("1:1").RowHeight = 25.5
    ActiveCell.FormulaR1C1 = " "
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp
        ActiveWorkbook.SaveAs Filename:="G:\IT\Trimit\Elastic\Feeds\Rab\inventory.csv", _
        FileFormat:=xlCSVMSDOS, CreateBackup:=False
    ActiveWindow.WindowState = xlMinimized
End Sub
I'd like each column to go through the loop once.

It's a currency column. I'd like the VB code, it's for a basic project.
Hi All,

I have a folder that receives many csv file extracts which I need to convert into xlsx files instead.

I have the code below which I found on one site, but I receive an error at line 3
Dim CSVfolder As String 

Open in new window

Expected end of statement

I haven't been able to test it yet, so I actually have no idea if this is even on the correct path or not...

Sub CSVtoXls() 

Dim CSVfolder As String 
Dim XlsFolder As String 
Dim fname As String 
Dim wBook As Workbook 

CSVfolder = "C:\Users\Desktop\3rd Party\Work Folder\" 
XlsFolder = "C:\Users\Desktop\3rd Party\Work Folder\xlsx\" 
fname = Dir(CSVfolder & "*.csv") 

Do While fname <> "" 

Set wBook = Workbooks.Open(CSVfolder & fname, Format:=6, Delimiter:=",") 
wBook.SaveAs XlsFolder & Replace(fname, ".csv", ".xls") 
wBook.Close False 
fname = Dir 

End Sub 

Open in new window

Thank you in advance
Hi All,

I am very new in PCOMM VB script and facing the below issue  which is creating obstacle to promote my code in  production...

I am invoking the below program(logcapture.mac) in a AS400 system after logging in to the main screen. It is running properly approx 36 Hrs and after that suddenly
getting stopped. Getting below error if trying to re-initiate from the same screen/session.

"PCSWS041 - The system has insufficient resources or the Script Engine is not properly installed"

But able  to re-initiate if I run with a fresh session by closing the previous.

DESCRIPTION=  ** TLPV - Log Capture v1.0 **

Dim Logger, Domain_Id, atm_LoginID, atm_LoginPassword

'Domaid_ID =============>

Domain_Id = "xxxxxxx.xxxx_xxx"
atm_LoginID = "xxxxxxx"
atm_LoginPassword = "xxxxxxxxx"



Dim Record_Low, Previous_Record_High, Record_High, Nw_Record_Low, Sub_System, Library, Current_ZNL, Pre_Library, Product, path, Node_Name, Nw_Node_Name, Iteration, s,nw_entry, filename,workpath, objFSO, RecordsFile, outFile, objFile,rAwdaTaU, rAwdaTaL,mystring,string_loop_count, k, Remaining_len, count, Logout_indicator
Set objFSO=CreateObject("Scripting.FileSystemObject")

Private sub Main()

Open in new window

Hi all,

I had a previous question where I needed to search a single folder for the 3 latest files in that folder then copy those 3 files to a new folder - this question got answered and the thread can be found here:


The next issue I have now is:

1) I have a main folder with 20 sub-folders

2) Everyday around 7AM, a new csv extract is added to each sub-folder

2) I need to search through each individual sub-folder and find the latest (the current days) file added to that sub-folder

3) I then need to copy each individual file from its respective sub-folder and place ALL the files in ONE folder - there's no chance of the filenames ever being the same

I found 2 solutions that work in their own way, but I need to "combine" the solutions.

Solution 1: This one will copy ALL files found in a single directory based on the current date to a separate folder

Option Explicit

Dim FolderToCheck, FolderDestination, FileExt, mostRecent, noFiles, fso, fileList, file, filecounter, oShell, strHomeFolder

' Enumerate current user's home path - we will use that by default later if nothing specified in commandline
Set oShell = CreateObject("WScript.Shell")
strHomeFolder = oShell.ExpandEnvironmentStrings("%USERPROFILE%")

'Variables -----
folderToCheck = strHomeFolder & "\Desktop\Terminations"           ' Folder Source to check for recent files to 

Open in new window

Train for your Pen Testing Engineer Certification
LVL 12
Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

I'm writing an HTA file to monitor two specific services on my local computer.  I'd like to add one process to it, but I don't think I can monitor process status with HTA.  That's a problem for later.  Right now, with my current code, everything works except the Start, Stop, and Restart buttons I have.  I would appreciate any ideas on how to get them working.  I changed to names of the monitored services in my code to Spooler and Fax for compatibility in case anyone wants to test it on their machine.  

<title>Server Services</title>
    APPLICATIONNAME="Server Services"

body {
    background-color: black;
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 25px;
table {
    width: 100%;
    border-color: firebrick;
    background-color: black;
    color: khaki;
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 12px;
th {
    border-color: firebrick;
    background-color: black;
    color: khaki;
td {
    border-color: firebrick;


<script language="VBScript">

Sub Resize()
    Window.ResizeTo 380,200
End Sub
Sub Window_OnLoad
    ' Populate table with list of services
    Window.ResizeTo 380,200
End Sub
Sub ListServices(sComputer)
    Set oTable = Document.All("list_servicenames")

    ' Delete any existing data rows

Open in new window

Hi Experts,

I am working on one requirement that need to create a interface file, I am coding in the VB. I am not  a familiar with the VB and need help.

The interface file - We need the auto generated sequence number for the file. ( EX: 00000001.txt)  Can we do it in the VB. every time the service generate a new sequence number that not used in previous.
For Example : I have the interface files like 00000001 - 00000012  then next it should crate with 00000013 and so...
if the service is restarted then the counter should not be zero. it should be continue with the same sequence number ( Do we need to use the database for store this (Or) is there any way that we can save the last sequence number in the memory)

Please suggest me on this requnirment.

This VB script looks at the begining of the subject and removes the mess that our IT dept adds to our email to notify us that the email came from an external source and should be handled with care.  Since I'm smart enough to do that without being reminded I personally want to remove that because an email conversation will end up with an additional string pre-pended to the subject line.    "RE: <EXT> Subject RE: <EXT> SubjectRE: <EXT> Subject RE: <EXT> Subject RE: <EXT> Subject RE: <EXT> Subject <EXT> Subject"  

Occasionally it throws an error that I haven't been able to trap and handle which causes the rule to be deactivated.  Any suggestions?

Sub Remove_EXT(myItem As MailItem)

    On Error GoTo Error_Handler
    Dim mySubject As String
    mySubject = myItem.Subject

If (Left(mySubject, 6)) = "<EXT> " Then
    mySubject = Right(mySubject, Len(mySubject) - 6)
End If

If (Left(mySubject, 5)) = "<EXT>" Then
    mySubject = Right(mySubject, Len(mySubject) - 5)
End If

If mySubject = "" Then
    Exit Sub
       myItem.Subject = mySubject
End If

Exit Sub


    MsgBox "An error occurred" & vbCrLf & vbCrLf & "Error Number: " & Err.Number & vbCrLf & _
    "Error Source: RemoveExternalPrefix " & "Error Description: " & Err.Description, vbCritical, "An Error has Occured!"
End Sub

Open in new window

Is there any possible to do the following execution using vbscript

1. Generally, we receive business data excel doc .xls or .xlsx (which doesn't have my code/macros in it)
2. I have created Master sheet (.xlsm) which has macros in it and no data.
3. Whenever i receive business data (1): i have to copy that into master sheet (2),SaveAs (.xls) as date stamp and run macros into the new one.
4. Master sheet should not be open while copying because i have wrote some line code in "BeforeClose" method in master sheet.
Please anyone help me out on this to achieve the above. Below is the my code
Dim objworkbookv
Dim objworkbookm
Dim objworkbookd
Dim ws
Set objExcel = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
objExcel.Visible = False
filePath = BrowseForFile()
If filePath = "" Then
MsgBox "You have not selected the file", vbcritical
Set objWorkbookv = objExcel.Workbooks.Open(filePath)
Set objWorkbookm =
For Each ws In objWorkbookv.Sheets
    ws.Copy objWorkbookm.Sheets(objWorkbookm.Sheets.Count)
objWorkbookv.Close False
filepath = left(filepath,instr(1,filepath,".xls")-1)
objWorkbookm.SaveAs (filepath & "_" & timeStamp & ".xls")
objWorkbookm.Close SaveChanges = True
Set objworkbookd = objExcel.Workbooks.Open(filepath & "_" & timeStamp &  ".xls")
objExcel.Visible = True
Hello, I'm attempting to write my first HTA script and in doing research I came across this thread:


I'm no programming or scripting expert by any means.. normally I can figure out what I need to do by researching and looking at examples I see on the internet.  So please excuse me if I say anything ignorant.  Now the HTA script I'm writing is incredibly similar to what the user "rejoinder" posted in the above mentioned thread.  So I copied the code and tried to run it on my computer so I can see exactly how it works to try and get an idea of how to make mine work, but all it did was launch the Windows MSI Installer.  I know it is something related to the CLSID in the object in the <BODY> section.  Removing the CLSID from the object will make the script run but it doesn't do anything.  I put the same CLSID into my HTA script I'm writing and that made it launch the Windows Installer also.  I don't know what I'm missing.  Any help in getting this script to work for me would be greatly appreciated.  Thanks in advance!
Looking for a script to find a specific word in a file and copy some text after it?


$This is a test - For something - Else

The script would find "$" and copy "$This is a test - For something" leaving out the rest.   Looking for the second "-" as a completion.  It would loop through the file and copy that data wherever it saw the criteria to a new file.
Experts, I am working within my Access DB and using VB to sum up the Cycle Times of a days worth of machine processes.  My DB records the finish time (long date) each time my CNC completes a job through the day, which I can use as the cycle time (ie. the difference between finish times of two adjacent job records).  However within my VB calculation I need to check if the cycle time included the employee's break or lunch and remove that duration from the cycle time.

For example, I have a two finish times as "12/1/2017 9:47:03 AM" and "12/1/2017 10:33:29 AM".  This calculates for 46.43 minutes, however it included a break time that occured from 10:00 am until 10:20 am which needs to be detected and removed from this particular cycle time.  Is there an easy way to check for the break time duration between a the cycle time?
Please help me find the error.

I am trying to pull the data from "raw data sheet" Column B and place it on "CFS Site" sheet Row 1 (starting at column C), but only if it does not already exist in the row.

The worksheet I am working on are attached below.

Sub AddSites()

Dim sws As Worksheet, dws As Worksheet
Dim slr As Long, dlc As Long
Dim Rng As Range, Cell As Range
Dim r
Application.ScreenUpdating = False
Set sws = Sheets("Raw Data Sheet")
Set dws = Sheets("CFS Site")

dws.Range("C1:P1").Value = ""
sws.AutoFilterMode = False

slr = sws.Cells(Rows.Count, 1).End(xlUp).Row

With sws.Range("A1").CurrentRegion
    .AutoFilter field:=1, Criteria1:=dws.Range("A2").Value
    If sws.Range("A1:A" & slr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
        Set Rng = sws.Range("B2:B" & slr).SpecialCells(xlCellTypeVisible)
        For Each Cell In Rng
            r = Application.Match(Cell.Value, dws.Range("c1:P1"), 0)
            If IsError(r) Then
                If Application.CountIf(dws.Columns(2), Cell.Offset(0, 3)) > 0 Then
                    If dws.Range("c1").Value = "" Then
                        dlc = 3
                        dlc = dws.Cells(1, Columns.Count).End(xlToLeft).Column + 1
                    End If
                    dws.Cells(1, dlc).Value = Cell.Value
                End If
            End If
        Next Cell
    End If
End With

sws.AutoFilterMode = False

End Sub
I need to delete net-snmp agent related components on 5000+ servers .. The older version of net-snmp don't have uninstall.exe . So i want to delete the net-snmp agent and it's folders

Can someone please help me with the powershell script to do the following action

1. execute .bat file which is stored on c:\usr   ( c:\usr\unregistersnmpagent.bat)
2.delete the entire folder c:\usr
3.uninstall a application using it's string value  msiexec.exe /x{443462CE-4A91-4C4C-967E-604270A1E531}
Hire Technology Freelancers with Gigs
LVL 12
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.


Is there any way to delete the history, drop-down list and cookies for Microsoft Edge through VB Script?

Thank you
I wish to display some images on a windows form in sequence but put a few seconds between them so as to give the user enough time to read them.  However, when I try to use the timer below between each image, the timer runs first at the start of the program instead of between the the image.  How can I get the program to pause between each display instead of at the beginning.

        Dim i As Integer
        For i = 1 To 5
hello team,
I need to have a .bat withe VBS that transforms the value of a line into column
And to do this I need to verify the column named country in my original file , for each county on my file i have 12 line and for those line i have 12 values and each value represent a month
for example in my original file
for the country "CHINA " i have 3 line for  each month( column named "date")
and i need to transform the value from line to column ..
in PJ my original file and an example of file after a manual transformation
thank you for your help .
My company has recently re-branded and I have created new PowerPoint, Excel and Word templates.
In Office I have created my colour palettes which are very useful, but these dont go across with the PowerPoint/Excel/Word files.

Ive been looking into it and it create an XML file on the machine with all the colours within that palette.
C:\Users\user\AppData\Roaming\Microsoft\Templates\Document Themes\Theme Colors\Name.xml

I would like an easy way for everyone else in the company to copy this XML onto their computer.

Can this be done with a batch script??

Any advice?

When I try to run the following command within Power Shell on a Windows 10 Pro OS I get the following error message.

What do I need to do to fix this so I will be able to successfully run this PowerShell command?

PS C:\support> Get-ChildItem "C:\Users\dstroble\AppData\Local\Temp\" | Get-NTFSAccessInheritance

Get-NTFSAccessInheritance : The term 'Get-NTFSAccessInheritance' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:57
+ ... m "C:\Users\dstroble\AppData\Local\Temp\" | Get-NTFSAccessInheritance
+                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-NTFSAccessInheritance:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\support>
Hello Experts,

I have a root folder which contains multiple .jar files. Those files are located in subdirectories folders.
I would like to set up a batch or a vbscript in which you report the name of the .jar file in a csv file and a result.csv file should be generated with the following attributes:

Example of result.csv

Reference root can be reported directly in the script.

Thank you very much for your help.

VB Script





VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.