VB Script

37K

Solutions

20K

Contributors

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

I would like to change this script, so that instead of hard coding in the destination email addresses, it will look into a flat txt file and use the email addresses listed in that specific file instead.


###SETUP START###
#-------DO NOT MODIFY-------#
    #Yesterdays Date
        $date = ((Get-Date).AddDays(-2)).ToString("MMM/dd/yyyy")
###SETUP END###

###USER VARIABLES START###
#-------MODIFY AS NEEDED-------#
    #Mail Subject
        $Subject = "Report: "+$date+" REVISED "
    #Body of Email
        $MessageBody = "REVISED - Report for $date. Thank you."
###USER VARIABLES END###

###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
Send-MailMessage -From 'email1@mail.com' -To 'email2@mail.com', 'email3@mail.com', 'email4@mail.com' `
  -SmtpServer 'smtp.mail.com' `
  -Subject  $subject `
  -body $MessageBody `
  -BodyAsHtml `
  -Attachment 'C:\Attachment\Attachment.pdf'
 ###PROGRAM END###

Thanks in advance for your assistance
0
Amazon Web Services
LVL 12
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Scheduled task won't run unless logged in on Windows Server 2016. I've researched this for several hours and I'm getting nowhere. This is calling a VBS script which runs just fine if you either run it manually, or set the scheduled task to run only when the user is logged in.

The user is a domain admin. I also tried activating the default administrator account and it also fails in the same way when using this account, too.

I've tried calling the script via a batch file.
I've ensured that the START IN folder is specified and that it has a trailing backslash.

I've also tried calling this as C:\windows\syswow64\cscript - with a variable of the path to the vbscript, and using the syswow folder as the START IN folder.

I'm at a loss to know what to try next. There's possibly a typo somewhere along the line, but the scheduled task does run if it's set to run only when I'm logged in - I would hope that this proves the parameters to be correct.

For information, the script calls a program called Snapshot.exe and this creates a volume shadow copy vss type backup to a folder. This will eventually be a network resource but I've reconfigured it to be a local drive location temporarily so that there's no confusion over network credentials.

Any ideas please?
0
I am developing a ASP.NET Web Forms / VB.NET app.  I am new to the ASP.NET portion of coding (I prefer to do as much of the coding in this project in VB.Net as possible) .  I am wanting to use a GridView with a column to click for a drill down.  I found some code online that seems like it should work with some tweaking.  I have it partially working.  It works for the main GridView, but not the drill down.

This is the link of the demo where I got the sample code showing how it works:  "https://www.aspsnippets.com/demos/308/"

Here is what I am getting on my webpage:
WebPage.JPG
Here is the code that calls the main GridView:
       
       ' Get main table data and bind to GridView control
        grdDelvImp.DataSource = GetData("SELECT * FROM " & gtblship_delay & "WHERE so_id = '" & strSO_IDIn & "'")
        grdDelvImp.DataBind()

Open in new window


GetData function:
    
Public Function GetData(query As String) As DataTable

        ' Open Connection To The Database
        If con Is Nothing Then
            open_db_connection()
        ElseIf con.State = 0 Then
            open_db_connection()
        End If

        Using con
            Using cmd As New SqlCommand()
                cmd.CommandText = query
                Using sda As New SqlDataAdapter()
                    cmd.Connection = con
                    sda.SelectCommand = cmd
                    Using ds As New DataSet()
                        Dim dt As New DataTable()
                 

Open in new window

0
I'm using the following code to copy files from one folder to another and receive the error message object required on line:
objfso.CopyFile strSource & strFileName, strDest, OverWriteExisting

Open in new window


strSource = "C:\Users\vincent.shields\Documents\MATS\dbs\"
strDest = "\\itio-ARL-fs01.itsc.hhs-itsc.local\alj_arlington\MATS\Testdbs"
For Each strFileName In Array("matsdbarl.accdb", "matsdosarl.accdb")
objfso.CopyFile strSource & strFileName, strDest, OverWriteExisting
Next


Set objfso = Nothing

Open in new window

0
I am pulling my hair out on parsing a JSON API response (from ShipStation) due to the arrays within the response object.  I have always used a JSON parser (from demon.tw) which works perfectly for accessing the various items in a JSON object, however it does NOT work with arrays because of the fact that it is using JScript one cannot loop with a variable index.

I have tried a few other JSON classes but still had no success in being able to easily loop through each order and pull the relevant order information for each.

Below is a sample of the JSON response from the API. Can someone please help me loop through the orders (only 2 orders in the array in the sample below), and populate all the necessary order variables on each loop, such as OrderID, Customer info, billing/shipping addresses, line items ordered, priciing etc.


Open in new window

0
Hi!  We are testing our existing files before upgrading from Office 2010 to Office 365 (Office 2016).

We have a complicated Excel frontend created by users to process data and automatically create charts and graphs and ultimately export everything directly to PowerPoint.

We have done a ton of testing but have only come across one problem that I can't seem to resolve.

VB code that copies and paste a chart from Excel to PowerPoint works in Office 2010 but not in 2016.  
Here's how the code currently exists in Office 2010.
        Set activeSlide = pp.ActivePresentation.Slides(1)
        ActiveSheet.Range("BX146:BY158").Select
        ActiveSheet.Range("BX146:BY158").Copy
        activeSlide.Shapes.PasteSpecial(DataType:=ppPasteOLEObject).Select

Open in new window

This gives us the following error in 2016.
Run-time error '424':
Object required
(also see screenshot in Word doc)

I read posts online and made the following code changes but ended up with the same error.
   
        Set activeSlide = pp.ActivePresentation.Slides(1)
        ActiveSheet.Range("BX146:BY158").Select
        ActiveSheet.Range("BX146:BY158").Copy
       '9/5/18 activeSlide.Shapes.PasteSpecial(DataType:=ppPasteOLEObject).Select 'Runs table
        '9/5/18
        Dim pptshape As PowerPoint.Shape
        Set pptshape = activeSlide.Shapes.PasteSpecial(DataType:=ppPasteOLEObject)
        pptshape.Select
        '9/5/18 end

Open in new window


As I said, this code runs fine in Excel 2010.

Does anyone have any ideas on how to resolve this issue?  Also, please note that we need to be able to paste the object (which is a table in Excel) so that PowerPoint links to the table in Excel and "sees" any updates that may be made in Excel to the table.

Thank you for your help.

Alexis
isummary-powerpoint-creation-error-.docx
0
Hi Experts ,

I have a  Independent folder in Outlook named "Test" .
I have macro whose work is to get the attachment from "Test" folder emails and save at"EmailAttachments" folder in "MyDocuments"

So the program is working when I manually run the macro , So I need your help to set some program which can run this macro automatically .
The program should run when new email comes in "Test" folder only otherwise if it will check inbox and all outlook then it will be performance issue.

I am using below code in "ThisOutlookSession" but it is checking all incoming emails in outlook , just need to check "Test" folder only.

Private Sub Application_NewMail()
    Call SaveAttachments
End Sub 

Open in new window



Also "Run as Script" is not available.


Appreciate any help in this regard.
0
Need help -

How to save the .xls file as .xlsx without opening it:

Below code is working properly and saving files but need to change the extension while saving .



Sub SaveLatestAttachment()
Dim olApp As Outlook.Application
Dim oMail As Outlook.MailItem
Dim NS As Outlook.NameSpace
Dim oFolder As Outlook.Folder
Dim SaveInFolderName As String
Dim SaveInFolder As String
Dim subFolderName As String
Dim strFile As String
Dim Item As Object
Dim Items As Outlook.Items
Dim x()
Dim i As Long

SaveInFolderName = CreateObject("WScript.Shell").SpecialFolders(16)
subFolderName = "EmailAttachments"
SaveInFolder = SaveInFolderName & "\" & subFolderName & "\"

Set olApp = New Outlook.Application
Set NS = olApp.GetNamespace("MAPI")
Set oFolder = NS.GetDefaultFolder(olFolderInbox).Parent.Folders("Test")
ReDim x(1 To oFolder.Items.Count, 1 To 4)
Set Items = oFolder.Items
Items.Sort "[ReceivedTime]", True
For Each Item In Items
    If TypeOf Item Is Outlook.MailItem Then
        Set oMail = Item
        If LCase(oMail.Subject) = "my daily report" Then
            If oMail.Attachments.Count > 0 Then
                For i = 1 To oMail.Attachments.Count
                    strFile = oMail.Attachments(i).FileName
                    If InStr(LCase(strFile), "my report") > 0 Then
                        MsgBox oMail.ReceivedTime
                        strFile = SaveInFolder & strFile
                        On Error Resume Next
                        Kill strFile
                 

Open in new window

0
Hi Experts,

This Program is saving the attachments from Independent Outlook folder to My Dcoumnets "EmailAttchments" folder.


The issue is , loop is checking at every run the whole folder emails one by one , In that folder I will get daily one email that have same subject suppose " My Daily Report" and I need that the program check latest email only and save (overwrite) the latest attachment on destination folder and avoid checking the whole email folder.

Appreciate your help.


Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim NS As Outlook.NameSpace
Dim srcOLFolder As Outlook.Folder
Dim i As Long
Dim lngCount As Long
Dim srcOLFolderName As String
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
Dim subFolderName As String
Dim sFileType As String
Dim dtDate As Date
Dim sName As String
       
       
   ' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    
    ' The attachment folder needs to exist
    ' You can change this to another folder name of your choice
    'Assuming  a folder called "Email Attachments" in your Document folder
    Set fso = CreateObject("Scripting.FileSystemObject")
    subFolderName = "EmailAttachments"
 
    '--------------------------------------------------
    'create the folder if it doesnt exists:
    Dim ttxtfile, txtfile, 

Open in new window

0
We are currently using an SSO kiosk software (Imprivata).  Windows automatically logs into windows using a shared AD account and then locks.  Individual users can then login with their own credentials to run software etc..  The problem is that when each user logs in, they do not have access to their home directory documents folder.  THe shared autologon account maps the AD drive throu GPO as it would for any other account on our network. The SSO software can incorporate VBS scripts during logon/logoff.

I am attempting to map their home directory folder, but having issue.  I can get all the way to the home$ folder, but not the username folder.  Attached is the script I am running.  It seems like there is something the system doesnt like about the %username% variable?

Option Explicit
Dim objNetwork, strRemotePath1
Dim strDriveLetter1
strDriveLetter1 = "M:"
strRemotePath1 = "\\cmc-vserver\home$\%username%"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
Wscript.Quit
0
Learn SQL Server Core 2016
LVL 12
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

I am using namespaces for the first time in a Visual Studio project, following a sample project tutorial and am struggling to use them.
(I usually don't bother specifying namespaces but am trying to do things "by the book"!)

My basic problem is that Visual Studio's intellisense doesn't like me doing a VB Imports statement with just the namespace I specify - it wants me to add the project name to the namespace to validate my code.  When I do this, my code can build successfully but I then get problems further down the line. Before getting to solving these latter problems, I'd like to understand why this namespace/imports behaviour is different behaviour to that of the sample code I'm trying to emulate.

The sample project that I am working with is:
getting-started-with-aspnet-45-web-forms
The complication is that I'm using Visual Studio 2017 and I'm translating all of the code to VB as I go!

In my code, I am specifying a Namespace in a vb file as:
Namespace WingtipToys.Models

    Public Class Product

    End Class

End Namespace

Open in new window


...but when I want to use it in an Imports statement on codebehind for another page, intellisense is insisting that I include the project name (also "WingtipToys")
Intellisense not happy with my code without adding the extra namespace.Intellisense suggests I change it to
Imports WingtipToys.WingtipToys.Models.Product

Open in new window

0
Greetings,
I have a question, how can I use the following script to take the name of my selected computer and restart it?

$pc = Get-ADComputer -Filter * -Property CN | Select-Object CN |
Out-GridView -OutputMode Single -Title 'Select PC To Reset'
Restart-Computer -ComputerName ""
2018-08-30_10-14-46.png
2018-08-30_10-14-51.png
2018-08-30_10-14-54.png
0
Set timer to run at 12 AM everyday in access how to do that. You can see the code and details in the below thread.
i want to run the macro everyday 12AM. I search for it and could not find how to run on specific time.

https://www.experts-exchange.com/questions/29115749/Loop-through-query-and-send-email-everyday-at-12AM.html
0
hello, i want Powershell script that give me list of all the computers in AD with the option of select one of them by number and after it i can change the computer name that i selected.

exsmple:
Get-ADComputer -Filter * -Property * | Select-Object CN
1. WS1
2. WS2
3. WS3
4. WS4
Select a PC: 2

Write-Host "Please enter your new computer name: "
$newname = Read-Host
## netdom renamecomputer $oldname /newname:$newname /userd:* /passwordd:* /usero:* /passwordo:* /reboot:10 /force
Rename-Computer -ComputerName "$oldname" -NewName "$newname" -DomainCredential amal-p\admin -Force -PassThru -Restart
0
Hello Guys,
I have a script which opens all excel files in folder and run a macro in all of them. Unfortunately it keeps asking me that the excel file is already opened and if I would like to reopen it. I wanted to kill the process, but it doesn't really work as it should. Even when I manually kill the process and run the script it is asking me again, if i would like to reopen already open file. The problem with opening of excel occurs in  Sub ProcessExcelFile(sFileName).
Could you please advise what should be changed in bellow code? Thank you.

here is the code:

Const sRootFolder = "C:\test\"

Dim oFSO, oFile 
Dim xlApp, xlBook, objWorkbook 

Start
 oShell.Run "taskkill /f /im EXCEL.EXE", , True



Sub Start()
     Initialize
     ProcessFilesInFolder sRootFolder
     Finish
 End Sub



Sub ProcessFilesInFolder(sFolder)
     ' Process the files in this folder
     For Each oFile In oFSO.GetFolder(sFolder).Files
         If IsExcelFile(oFile) Then ProcessExcelFile oFile.Path
     Next
 End Sub



Sub Initialize()
     Set oFSO = CreateObject("Scripting.FileSystemObject")
     Set xlApp = CreateObject("Excel.Application")   
 End Sub



Sub Finish()
     xlApp.Quit
     Set xlBook = Nothing 
     Set xlApp = Nothing    
     Set oFSO = Nothing
 End Sub

Function IsExcelFile(oFile)
     IsExcelFile = (InStr(1, oFSO.GetExtensionName(oFile), "xls", vbTextCompare) > 0) And (Left(oFile.Name, 1) <> "~")
 End Function

Sub ProcessExcelFile(sFileName)   
     Set xlBook 

Open in new window

0
I need count of different word styles in the word document as a CSV file with column headers Style name and Styles Count.

My VB code for output as a popup for particular style in the word document.

   
Sub Count()
    Dim l As Long
    ResetSearch
    With ActiveDocument.Range.Find
       .Style = "Strong" 'Replace with the name of the style you are counting
       While .Execute
          l = l + 1
          If l > ActiveDocument.Range.Paragraphs.Count Then
             Stop
          End If
       Wend
    End With
    MsgBox l
    ResetSearch
    End Sub
    
    Public Sub ResetSearch()
    With Selection.Find
       .ClearFormatting
       .Replacement.ClearFormatting
       .Text = ""
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
       ' plus some more if needed
       .Execute
    End With
    End Sub

Open in new window


Please suggest that different styles in word not only strong any type of style count in csv format column headers are Style name and Styles Count
0
Can you please help?

I have a workbook that contains dynamic number of sheets.
Each sheet contains three pivot tables, these pivot tables have three source sheets.
All three source sheets have one column in common the customer ID, and therefore, the three pivot tables are filtered on Page Filed “GL_ID”, i.e. customer ID.  
Every day, we run another macro that compiles a dynamic list of customer IDs, and out of this list, we create a changeable number sheets, this macro also pastes three pivots on those sheets, it also prints the customer ID on cell B2 of each sheet (each sheet contains, (1) balance, (2) possible trading activity and (3) possible product change reports of a customer).
-      Pivot table one contains;  all customer IDs
-      Pivot table two and three, however, may or may not contain every customer ID printed on cell B2.
What I would like to do and kindly ask your help, is a macro that filters each pivot table in each sheet, by setting the page fields equal to the value of cell B2?
But also importantly before that, it tests, if the pivot item in cell B2 is to be found in the drop down list of the pivot tables (page field), epically on pivot table two and three .
-      If the pivot Item is found = filter each pivot table based on cell B2.
-      Else ignore and go to the next pivot table.
Thank you in advance,
Regards,
Jay
0
I am trying to have a vbscript file read a log file that has a file name in it.  Then I would like to change the name of the file in the directory to be the new name from the file.  Any suggestions would be greatfull .  I get an error each time saying bad file name or number on line 16

Const ForReading = 1


Set objFSO = CreateObject("Scripting.FileSystemObject")


Set objFile = objFSO.OpenTextFile("T:\365\rename\testrename\Log.txt", ForReading)

strCharacters = objFile.Read(70)
msgbox strcharacters
objFile.Close


strNewName = strCharacters
msgbox strnewname
objFSO.MoveFile "T:\365\rename\testrename\agood" , strNewName

Open in new window

0
In Word's Visual Basic macro, I want to do a Find for a unique text and then highlight.  I'm a novice and could not find how to show in an IF statement, IF the text is found, progress with the statements that highlight the text and if nothing is found, don't.  Thanks.
0
Exploring ASP.NET Core: Fundamentals
LVL 12
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Exchange 2010

I have a set of custom forms written in vbscript that are used to manage contacts, quotes, etc and mass email them when needed.  The issue I am having is specific to Outlook 2016.  Upon completion of the vbscript, a comma separated list of email addresses is added to bcc on a new email.  When the email is sent, outlook 2016 will give a bounce back with all of the email addresses listed.  Only the first email appears to go through.  I think this is related to the autocomplete contacts feature in newer versions of outlook.  If I send from outlook 2007, the email goes through without issue.  I need 2016 clients to be able to send these as well.

I'm not sure what other information would be relevant to helping you help me, so please let me know.

Thank you,

Reade
0
I have a VbScript that creates an Excel Spreadsheet and writes in formula. I have a formula that I am trying to add a function with it but it does not give me the result I am looking for. The below formula should add the current date whenever approved w/ comments or approved is selected, but at the time of creation it hard codes the date for the creation date instead.  Experts please tell me what I am doing wrong.

Formula:  

objSheet.Cells(5, 2).formula = "=IF(G7=" & Chr(34) & "Approved w/Comments" & Chr(34) & ","  & chr(34) & FormatDateTime(Now(),vbShortDate) & Chr(34) & ",IF(G7=" &chr(34)& "Approved" &chr(34)& "," &chr(34)& FormatDateTime(Now(),vbShortDate) &chr(34)& "," & chr(34) & chr(34) & "))"

Output:
=IF(G7="Approved w/Comments","8/21/2018",IF(G7="Approved","8/21/2018",""))
0
When I go to log onto a web page this is what I get ,

Microsoft VBScript runtime error '800a005e'
Invalid use of Null: 'clng'
/index.asp, line 463
0
How can I get the below "Desired Steps" #2 to work ?

Current Steps
1. enter "this is a test to delete THIS word I did by mistake" into CELL B1 in an EXCEL 2013 file
2. hit LEFT arrow on keyboard to delete the above "THIS" text
3. CELL A1 becomes active

Desired Steps
1. enter "this is a test to delete THIS word I did by mistake" into CELL B1 in an EXCEL 2013 file
2. hit LEFT arrow + something on keyboard
3. cursor appears behind the word "mistake", allowing me to LEFT arrow to "THIS" and backspace to remove "THIS"
0
Does anyone know of a program that will take all the attachments in Outlook and copy them to an external folder- we are trying to locate a high volume of missing documents the majority of which should be in email.
0
The path below is where I need to sync to:
This PC\SM-N920V-TheNote5\Phone\Documents

Open in new window


I need an automated way to sync files to a "Portable Media Player" connected to a Windows 10 PC.

The "Portable Media Player" is actually as Samsung Galaxy Note 5: an Android device.

Drag and drop works just fine, but I need to truly automate the process.

I can use VBA built in to MS Access, VB script or even a good fashioned batch file.

NOTE: I use SyncBack to synchronize some folders on my system, but it will not recognize the path to the Note5.
0

VB Script

37K

Solutions

20K

Contributors

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.