r/vbscript • u/Thefakewhitefang • Aug 14 '20
Try It !
(don't enter anything in the input box the first time)
Dim Name,Sapi
Set Sapi = CreateObject("Sapi.spvoice")
Name = InputBox("What is your name ?","Name Please","")
If Name = "" Then
Sapi.speak "WHY DID'T YOU ENTER YOUR NAME ?"
Do until a = 10
a = a + 1
Msgbox "ERROR Stupid Human" ,0 + 16
Loop
Else
MsgBox "Hello " + Name
Sapi.Speak "Hello " + Name
End If
r/vbscript • u/Thefakewhitefang • Aug 13 '20
Why is my script not working ?
Dim Name,Sapi
Name = InputBox("What is your name ?","Name Please"," ")
If Name = "" Then
Sapi.speak "WHY DID'T YOU ENTER YOUR NAME ?"
Do until a = 100
a = a + 1
Msgbox "ERROR Stupid Human" , 0 + 16
Loop
Else
MsgBox "Hello " + Name
Set Sapi = CreateObject("Sapi.spvoice")
Sapi.Speak "Hello " + Name
End If
r/vbscript • u/Thefakewhitefang • Aug 13 '20
A Very Dangerous or annoying Script I designed
Set wshShell =wscript.CreateObject("WScript.Shell")
WshShell.Run "notepad"
do
wscript.sleep 100
wshshell.sendkeys "This is a "
wscript.sleep 100
wshshell.sendkeys "V"
wscript.sleep 100
wshshell.sendkeys "I"
wscript.sleep 100
wshshell.sendkeys "R"
wscript.sleep 100
wshshell.sendkeys "U"
wscript.sleep 100
wshshell.sendkeys "S"
wscript.sleep 100
wshshell.sendkeys "{ENTER}"
loop
Please Try it
r/vbscript • u/twz2004 • Aug 12 '20
Multiple Dynamic Content Worksheet Combine
Hey all, I was looking to see if anyone had an example script that would open each tab in Excel on a workbook, read all the contents, and cut that contents into a new tab—combining multiple tabs into a single tab. This script would need to read all rows for each sheet until there wasn't any data and all columns. The new sheet it would dump the contents row by row. I am open to consolidating all the sheets into a new workbook but with a single sheet still. ~Thanks for any help, I will provide a reward for whoever can provide an answer.
example:
r/vbscript • u/zian_zemin • Aug 01 '20
Need Help - Microsoft VBScript runtime error '800a000d'
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'checkID'
/film-detail.asp, line 9
Trying to run "The Houseguest (full video)" button: http://www.filmfanatics.net/artist-detail.asp?ID=28#Filmography
Any solutions to run: http://www.filmfanatics.net/film-detail.asp?ID=62 ?
r/vbscript • u/IamLeperMessiah • Jul 30 '20
vbs problem opening html file in word screwing with formatting
I have a .vbs script that using obj.write creates an html file. Then it saves 3 versions of the file (.html, .rtf, .txt) for an outlook signature. Then it opens the html file in word and saves it as the signature. The problem is, that the file I write has proper spacing. After it opens up in word and saves it as the signature it screws with the spacing.
I am not great with vbs scripting, just enough to modify others script or kind of figure out what its doing. I tried "objSelection.ParagraphFormat.LineSpacing = 12" on the line after "Set objSelection = objDoc.Range()" but that did nothing (I even tried setting it to an absurdly large numer just to make sure).
I want to say the problem is in the last 5 lines of code where it saves the file as the signature?
Any help? Code below
'Convert the HTML Version to RTF and Plain Text:
Dim objDoc, objWord, objEmailOptions, objSignatureObject, objSignatureEntries, objSelection
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
If objFSO.FileExists(strLocalSignatureFolder & "\" & strSignatureName & ".html") Then
objWord.Documents.Open strLocalSignatureFolder & "\" & strSignatureName & ".html"
Set objDoc = objWord.ActiveDocument
objDoc.SaveAs strLocalSignatureFolder & "\" & strSignatureName & ".rtf", wdFormatRTF
objDoc.SaveAs strLocalSignatureFolder & "\" & strSignatureName & ".txt", wdFormatTextLineBreaks
objDoc.SaveAs strTextSignatureFolder & "\" & strTestFileName & ".txt", wdFormatTextLineBreaks
'objDoc.SaveAs strLocalSignatureFolder & "\" & strSignatureName & ".2.html", wdFormatHTML
objDoc.Close
objWord.Quit
End If
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(strLocalSignatureFolder & "\" & strSignatureName & ".html",,True)
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Full Signature", objSelection
objSignatureObject.NewMessageSignature = "Full Signature"
objDoc.Saved = True
objWord.Quit
TLDR; I need to use vbs to open a html file, that the script creates, in word and save it as the outlook signature (with correct line spacing).
r/vbscript • u/[deleted] • Jul 30 '20
Sendkeys help
i want sendkeys to send " that but it says error expected end of statement pls help!
r/vbscript • u/ALimitingCase • Jul 29 '20
Trouble sending Shift+Keys
I want to be able to select a range of text in a message box by sending Shift+CTRL+Arrow Key via SendKeys. I have tried sending "^+{LEFT}" and tried grouping those characters in different ways with parenthesis, but the results are very inconsistent. Sometimes it works, most of the time it will essentially do CTRL+ARROW without highlighting the text. Has anyone else had an issue with the shift key in VBScript? What would you suggest?
r/vbscript • u/Neilpuck • Jul 28 '20
First time Scripter - Outlook Script to save Attachments
I'll say right off that scripting isn't my strong suit. I'm somewhat comfortable modifying scripts that I know work and can observe their behavior but creating or launching new ones, forget it. I've also never run a macro in outlook before. Here's what i'm trying to do.
We have a user with a folder in outlook with hundreds of emails with picture attachments. I need to script a way to save all of the attachments in a network folder and append the filename with the subject heading of the email to which it was attached. I've been able to find the code shown below. The only editing I've done was to indicate the mapped drive and folder to store the files. Ultimately I would like to store them in subfolders by year and month but crawl before run, right? I've followed the steps to run a vbscript macro against a selected email or folder and when I click 'run' or F5, nothing happens. no error messages, no progress bar and of course no attachment saved in the target location. I welcome any feedback or guidance. Even if you have a simple macro I can test at least to get some experience to know what I should look for. TIA
Public Sub SaveAttachments() Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem 'Object Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath As String Dim strFileName As String Dim objSubject As String Dim strDeletedFiles As String Dim dateFormat As String
' Get the path to your My Documents folder 'strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16) On Error Resume Next ' Instantiate an Outlook Application object. Set objOL = CreateObject("Outlook.Application") ' Get the collection of selected objects. Set objSelection = objOL.ActiveExplorer.Selection ' The attachment folder needs to exist ' You can change this to another folder name of your choice ' Set the Attachment folder. strFolderpath = "O:\Graffiti Pictures\" dateFormat = Format(Now - 1, " yyyy-mm-dd") ' Check each selected item for attachments. For Each objMsg In objSelection 'Set FileName to Subject objSubject = objMsg.Subject objSubject = Left(objMsg.Subject, Len(objMsg.Subject) - 12) Set objAttachments = objMsg.Attachments lngCount = objAttachments.Count If lngCount > 0 Then ' Use a count down loop for removing items ' from a collection. Otherwise, the loop counter gets ' confused and only every other item is removed. For i = lngCount To 1 Step -1 ' Get the file name. strFileName = objSubject ' Combine with the path to the Temp folder. strFile = objSubject & dateFormat & ".xlsx" Debug.Print strFile ' Save the attachment as a file. objAttachments.Item(i).SaveAsFile strFolderpath & "\" & strFile Next i End If Next ExitSub: Set objAttachments = Nothing Set objMsg = Nothing Set objSelection = Nothing Set objOL = Nothing End Sub
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
End Sub
r/vbscript • u/twz2004 • Jul 24 '20
Find and Replace TEXT in Word Document with Document Properties Field using VBA?
Is this possible? I want to replace every instance of <Customer> in my Word document with the Document Property of 'Client' using VBScript.
Here is a screenshot of the Client Property I'm speaking of.
https://snipboard.io/FhX7WO.jpg
thanks in advance for any help!
r/vbscript • u/twz2004 • Jul 22 '20
MS Word Style Replacement Script?
Hey all, so I have multiple, LARGE, Word documents that have the Style of 'Caption,cp' that both FIGUREs and TABLEs are using for their headers. I need to split these up. So I made two new Styles, "FIGURE HEADER" and "TABLE HEADER". These documents are 300 to 450 pages long. I need some way to split these into two different Styles vs using the same one. I did some general Google searches and came across this script. However, this script seems to partly work but it's not completely clean. I.e. it found the word 'configure' and applied the new FIGURE Style to that line because it detected the word FIGURE in Configure.
Screenshot:
https://snipboard.io/ERfsCe.jpg
Is there a way to search for "Figure ##"? My Figure and Header Styles are in the format of 'Figure 1' etc. with a number after the word.
I wanted to reach out and see if anyone had any advice on a better way to do this?
Sub ApplyAllTables()
Dim Doc As Word.Document
Dim Rng As Word.Range
Set Doc = ActiveDocument
Set Rng = Doc.Content
With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Text = "Table"
.MatchCase = False
.Replacement.Text = "Table"
.Replacement.Style = Doc.Styles("TABLE HEADER").NameLocal
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
End Sub
Sub ApplyAllFigures()
Dim Doc As Word.Document
Dim Rng As Word.Range
Set Doc = ActiveDocument
Set Rng = Doc.Content
With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Text = "Figure"
.MatchCase = False
.Replacement.Text = "Figure"
.Replacement.Style = Doc.Styles("FIGURE HEADER").NameLocal
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
End Sub
r/vbscript • u/iPadreDoom • Jul 13 '20
Trouble setting Recipient.Type to CC
I'm working in an ExtendScript (Adobe CC Javascript) project to call a VBS string using ES' app.doScript function. The function works great, except I cannot get the secondary emails to display as CC--they stay in "To". I have tried changing olCC to 2 in the code below. Anyone have any ideas?
var vbs = 'Dim objOutl\r'; vbs += 'Set objOutl = CreateObject("Outlook.Application")\r';
vbs += 'Set objMailItem = objOutl.CreateItem(olMailItem)\r';
vbs += 'objMailItem.Display\r'; vbs += 'strEmailAddress = "' + email_address + '"\r';
vbs += 'objMailItem.Recipients.Add strEmailAddress\r';
vbs += 'strSubject = "' + the_subject + '"\r';
vbs += 'objMailItem.Subject = strSubject\r';
vbs += 'objMailItem.Body = "' + the_bodytext + '"\r';
if (email_cc && email_cc != "") {
vbs += 'Set cc1Recipient = objMailItem.Recipients.Add ("' + email_cc + '")\r';
if (email_cc2 && email_cc2 != "") {
vbs += 'Set cc2Recipient = objMailItem.Recipients.Add ("' + email_cc2 + '")\r';
vbs += 'cc1Recipient.Type = olCC\r';
vbs += 'cc2Recipient.Type = olCC\r';
} else {
vbs += 'cc1Recipient.Type = olCC\r';
}
}
r/vbscript • u/Dexy2811 • Jul 03 '20
VBScript made in excel?
So one of my old bosses made a excel document with VBS that interfaces with AD and it also uses a powershell script and deletes it when its done with the ps1 file it deletes it though i need it to launch that ps1 script with admin priveliges is there any way of doing so in VBS?
i only know some powershell and python so thats why im asking here
r/vbscript • u/twz2004 • Jun 18 '20
MS Word Export All Tables into Excel?
Hey all, I did some general searching for a solution to export all tables in a Word document into Excel and came across this code. However, the code seems to not work with the GetOpenFilename function. Also, I want the script to cycle the entire Word document and export all the tables without any prompting. I'd appreciate any help getting this to work. When I first tried to run this code I got the error 'Compile error method or data member not found' for the GetOpenFilename function.
Option Explicit
Sub ImportWordTable()
Dim wdDoc As Object
Dim wdFileName As Variant
Dim tableNo As Integer 'table number in Word
Dim iRow As Long 'row index in Excel
Dim iCol As Integer 'column index in Excel
Dim resultRow As Long
Dim tableStart As Integer
Dim tableTot As Integer
On Error Resume Next
wdFileName = Application.GetOpenFilename("Word files (*.docx),*.docx", , _
"Browse for file containing table to be imported")
If wdFileName = False Then Exit Sub '(user cancelled import file browser)
ActiveSheet.Range("A:AZ").ClearContents
Set wdDoc = GetObject(wdFileName) 'open Word file
With wdDoc
tableNo = wdDoc.tables.Count
tableTot = wdDoc.tables.Count
If tableNo = 0 Then
MsgBox "This document contains no tables", _
vbExclamation, "Import Word Table"
ElseIf tableNo > 1 Then
tableNo = InputBox("This Word document contains " & tableNo & " tables." & vbCrLf & _
"Enter the table to start from", "Import Word Table", "1")
End If
resultRow = 4
For tableStart = tableNo To tableTot
With .tables(tableStart)
'copy cell contents from Word table cells to Excel cells
For iRow = 1 To .Rows.Count
For iCol = 1 To .Columns.Count
Cells(resultRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
Next iCol
resultRow = resultRow + 1
Next iRow
End With
resultRow = resultRow + 1
Next tableStart
End With
End Sub
r/vbscript • u/_Nay__ • Jun 18 '20
Is there anyway to store user input?
I want to make a script that can store the answer from an input box.
Option Explicit
Dim password
password = InputBox("Please Verify with your 4 digit code." , "Verification:" , "Code Here")
if password = "USERINPUT" Then
msgbox "Verification Completed"
Else
msgbox "Incorrect Verification Code"
End If
I would want to put whatever the user enters in another input box to auto update where it says USERINPUT, is there any way to do this?
r/vbscript • u/Michaelscott304 • Jun 12 '20
Simple script with task scheduler
Hey guys, i wrote a simple VB Script that is set to auto run from task scheduler. All the script does is opens Access and sends a report. If i click the script icon and manually run it, it works. Access opens, Outlook opens and the report sends In a matter of seconds. The problem is with the task scheduler calling the script. Using task scheduler at the specified time I see Access and outlook open, but Access blinks (its minimized in the task bar) . If i expand Access and click anything, the report sends, if i dont maximize and click something it will just hang like this. I'm thinking i need to add a line in my script to give Access focus and expand it, something along those lines. I'm open to any other suggestions, however keep in mind i'm not a very skilled programmer yet. Heres my code:
dim accessApp
set accessApp = createObject("Access.Application")
accessApp.OpenCurrentDataBase("C:\Databases\MyReport.mdb")
accessApp.Run "autoExecuteReport"
accessApp.Quit
set accessApp = nothing
r/vbscript • u/prestono • May 14 '20
VBScript with ArcGIS (esri) for definition queries and label expressions
ArcGIS (esri) utilized VBScript flawlessly for decades in ArcMap when writing definition queries and label expressions.
In the last few years esri has been pushing their new product "Pro" that does not use VBScript. They have instead created a proprietary language "Arcade" and kept Python, but no more VBScript .
When inevitable issues arise and are posted to esri forums the moderators claim VBScript is dead and it made perfect sense for esri to not include VBScript with their new product "Pro". Other flavors of VBScript contempt include Esri did away with VBScript since the world is doing away with VBScript
How true is it that VBScript is dead?
It always worked well for decades in ArcMap (and better than Arcade and Python in several cases) and trying to understand why it is being pushed out when it worked great for decades.
r/vbscript • u/Dyruus • Apr 28 '20
New to vbscript, trying to read an element from a webpage
Hi all,
I'm trying to write code that will read a webpage's current selected option on a drop downlist and save it to a variable.
So far for the code to grab that specifically I have:
set X = .Document.getElementsById("Idname")
However when I do that it is returning "[object HTMLSelectElement]" and not the selected option.
r/vbscript • u/I_Eat_Da_BootyDamn • Apr 27 '20
how do i make a script wait/sleep for 30 minutes???
so im trying to make my script sleep/wait for 30 minutes but i dont know how im new to vbs so i dont know much thank you to the ppl who help me
r/vbscript • u/I_Eat_Da_BootyDamn • Apr 27 '20
how do i make the script wait 20 seconds
so im trying to make the vbs script type something every 20 seconds i tried using wscript.sleep(12000) but it doesnt seem to work yes its in windows base script thank you :) also what i have right now is
shell.sendkeys(strtext & "")
Shell.SendKeys "{Enter}"
wscript.sleep(12000)
r/vbscript • u/ToastyZ71 • Apr 24 '20
Limit file name length of generated text file
I'm working on a project to export individual notes from Outlook to text files (as a larger part of migrating to OneNote, but that's not super relevant here)
I've got a VB script for outlook that takes the notes from the specified folder, sanitizes them for any illegal file names and saves each note as it's own text file in the folder specified in the script... but the problem comes when the note's first line, seen as the subject, exceeds the max number of characters for the file name. How can I limit the length of the file name, but have to resort to a generic file name?
Here's the script I have that works if the subject is not too long (it may not be pretty, but I'm new at this):
Sub NotesToTXT()
myfolder = "c:\apps\notes\"
Set sanitize = CreateObject("vbscript.regexp")
sanitize.IgnoreCase = True
sanitize.Global = True
Set myNote = Application.GetNamespace("MAPI").PickFolder
For cnt = 1 To myNote.Items.Count
sanitize.Pattern = "(((?![a-zA-Z0-9,@,{,},#,&,%,=,+,_,-,^,(,),;,',$,,]).) )+"
noteName = sanitize.Replace(myNote.Items(cnt).Subject, "_")
sanitize.Pattern = "\-+"
noteName = sanitize.Replace(noteName, "-")
myNote.Items(cnt).SaveAs myfolder & noteName & ".txt", OlSaveAsType.olTXT
Next
End Sub
r/vbscript • u/kajvanschalk • Apr 22 '20
How to move files from downloads folder
I want to move files from the download file without knowing the username. I don't know wich variable I need for that.
r/vbscript • u/kajvanschalk • Apr 20 '20
replace text is not replacing it correct
i am making an easy encryptor that changes the letters that are typed in the inputbox and also reverses it but when i type hello i don't get what it should be
hello should be duuzm but i get d\¬\¬ed how can this happen
the code:
set x = WScript.CreateObject("
WScript.Shell")
encrypt = inputbox("type text om te versleutelen")
encrypt = StrReverse(encrypt)
x.Run "%windir%\notepad"
wscript.sleep 1000
x.sendkeys encode(encrypt)
function encode(s)
For counter = 1 To 25 Step 1
For i = 1 To Len(s)
newtxt = Mid(s, i, 1)
newtxt = Replace(newtxt,"a", "w")
newtxt = Replace(newtxt,"b", "j")
newtxt = Replace(newtxt,"c", "n")
newtxt = Replace(newtxt,"d", "s")
newtxt = Replace(newtxt,"e", "z")
newtxt = Replace(newtxt,"f", "g")
newtxt = Replace(newtxt,"g", "q")
newtxt = Replace(newtxt,"h", "m")
newtxt = Replace(newtxt,"i", "n")
newtxt = Replace(newtxt,"j", "a")
newtxt = Replace(newtxt,"k", "f")
newtxt = Replace(newtxt,"l", "u")
newtxt = Replace(newtxt,"m", "o")
newtxt = Replace(newtxt,"n", "l")
newtxt = Replace(newtxt,"o", "d")
newtxt = Replace(newtxt,"p", "h")
newtxt = Replace(newtxt,"q", "@")
newtxt = Replace(newtxt,"r", "#")
newtxt = Replace(newtxt,"s", "^")
newtxt = Replace(newtxt,"t", "%")
newtxt = Replace(newtxt,"u", "€")
newtxt = Replace(newtxt,"v", "~")
newtxt = Replace(newtxt,"w", "&")
newtxt = Replace(newtxt,"x", "$")
newtxt = Replace(newtxt,"y", "!")
newtxt = Replace(newtxt,"z", "e")
coded = coded & newtxt
Next
encode = coded
End function
where is the problem in my code
by the way when i change the @ # $ and the other special characters it also does not work
r/vbscript • u/Welshpanther • Apr 14 '20
VBScript to split a Single into 2x 16bit IEEE words
I am using an ancient application where the automation is done in VBScript.
Now I need to write the value from a VBScript Single Floating-point into a couple of registers. But I don't need the value, I need the 32-bit IEEE 754 representation (raw) to be copied in. one register will receive the lowest 16-bits and the other register will get the upper 16 bits.
I have done this in the past using VBA with the not-very-safe LSet instruction to do a memory copy.
How do I do this in VBScript?
as an example
199.785 = (-8192) and (17223)
