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: IP Lookup
LVL 12
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.
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 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

Free Tool: Site Down Detector
LVL 12
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

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
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.
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}

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 .
check bitlocker staus and pop up message its not encrypted in vbs or bat file

help will be aporeacited

Then log out current user
Need to password protect multiple Excel Files at one time, I have a script already, but if a file is already password protected or open I need the script to skip that file and continue.
I can make sure files are closed from the server actually, so it's more important that if a file is already password protected that it just skip over it and continue to the next if possible.

This is the macro/script:

Const cstPass As String = "Your Password Here"
Const cstRoot As String = "Your Directory Path Here"
Dim aFiles() As String, iFile As Integer

Sub ListAllFilesInDirectoryStructure()
  iFile = 0
  ListFilesInDirectory cstRoot & "\"
End Sub
Sub ListFilesInDirectory(Directory As String)
  Dim aDirs() As String, iDir As Integer, stFile As String
  ' use Dir function to find files and directories in Directory
  ' look for directories and build a separate array of them
  ' note that Dir returns files as well as directories when vbDirectory specified
  iDir = 0
  stFile = Directory & Dir(Directory & "*.*", vbDirectory)
  Do While stFile <> Directory
    If Right(stFile, 2) = "\." Or Right(stFile, 3) = "\.." Then
      ' do nothing - GetAttr doesn't like these directories
    ElseIf (GetAttr(stFile) And vbDirectory) = vbDirectory Then
      ' add to local array of directories
      iDir = iDir + 1
      ReDim Preserve aDirs(1 To iDir)
      aDirs(iDir) = stFile
    ElseIf InStr(LCase(stFile), ".xl") > 0 Then ' any excel file
      ' add …
Free Tool: Port Scanner
LVL 12
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

How do I Creating ODBC DSN Mysql Connector programmatically Not the sql server but the mysql
I'm trying to find a script that will allow me to join about 30 PC to the domain with powershell or other methods.
I try two different power shell scripts and I get this error ps1 cannot be loaded because running scripts is disabled on this system.
I try to add on the beginning of the script the following line but that did not help. Set-ExecutionPolicy Unrestricted.
I also use Kaseya to push scripts and I found a few scripts on txt format but they need to be under XML format so I convert a txt file to a xml file online but that did not work eider.
Any suggestion how I can achieve that by pushing a script to all PC's.
The script can be push and execute it by Kaseya VSA as long as the script works.

I have a vbscript that I run out of Outlook 2010 to open a word doc and populate the subject line.   It's works fine.

objDoc.MailEnvelope.Item.Subject = "test"

However, in Outlook 2013 I get a fatal error and Outlook crashes.  Any ideas?

Thank you,
when i was making a calculator in vb
overflowerror came
in division
how to resolve it
plz give me your email to send a photo to you about the problem
i need to Create code to randomly generate year and month and write to the database.
Generate ID’s and write to the database.
Loop 20 times.
Hi All,

I'm trying to make a Macro which allows the user to enter a keyword in a text box, click a command button and the macro then filters the results from a data set (in a table on another sheet) using Slicers and returns all entries which have the word (or a near match).

I'm using a separate column in the data set which is fed from the text box with the formula - ISNUMBER(SEARCH(Keyword,[@Description])) where Description is the field in which to search. This returns a True / False basis the word being available in the description and the Macro selects the True slicer.

The problem I face is when a word which is not in the description field is entered. What I want to understand is how to do the following -

1) Allow near matches - if the person searches for "Airlines" instead of "Airline" the result should show cases with the word airline present
2) Error handling - If the person enters a word not present in the description field, the marco should through up a pop-up saying the word is not present and ask the person to enter another word.

The code I am using is given below. I have also attached a sample file. Any help would be appreciated.

Private Sub getresults_Click()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
  ws.Visible = xlSheetVisible
Next ws
Application.GoTo ActiveSheet.Range("A1"), True

End Sub

Sub iskeyword()

    With ActiveWorkbook.SlicerCaches("Slicer_IsKeyword")

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.