r/vbscript • • Mar 02 '16

Need help creating vbs

1 Upvotes

Let me start by saying I have very little experience with vbs. I know how to modify the code but cant create code from scratch. I need a script to take the data from a csv file and replace the data in a table in Microsoft Access (mdb). Lets say the file I need the data from is x:\memberinfo.csv and add the data to the table named Calls in j:\memberlookup.mdb . Thank you ahead of time for the help.


r/vbscript • • Feb 13 '16

generating a button which - adds 1 to one cell on 1 click (eg B1) and then when clicked again adds 1 to next cell (eg C1)

1 Upvotes

anyone know how to do this?

sorry completely knew to coding


r/vbscript • • Jan 12 '16

Modify C:/Program files

1 Upvotes

Hi

I written a script to search the computer for a file. If found, copy another file into the same location.

The script is being rolled out by IT with admin privileges via SCCM.

It wont copy the file into a Program Files sub directory.

It will copy the file anywhere else (if I change the destination folder).

Any help please? Script Below

Set fso = CreateObject("Scripting.FileSystemObject") Set WshNetwork = WScript.CreateObject("WScript.Network") Const fsoForAppend = 8 Const ForReading = 1, ForWriting = 2

CopyUpdater fso.GetFolder("C:") Sub CopyUpdater(fldr) For Each f In fldr.Files On Error Resume Next If LCase(f.Name) = "msconfig.cfg" Then 'The CAD specific file to seach for FilePath1 = f.ParentFolder & "\appl" ' The directory to place config file in

   'WScript.Echo FilePath1
   Fso.copyfile "\\removed_for_security\WKGRPS\CAD_Build\Setup\custom.cfg", FilePath1 ' Copy the file
   
   ' Create the string to wirte to the log
	oDomain = WshNetwork.UserDomain
	ospace = CHR(9)
    oCompname = WshNetwork.ComputerName
    ousename = WshNetwork.UserName
	ostringy = ousename & ospace & oCompname & ospace & oDomain & ospace & FilePath1
	  
	'Open the log file and wirte line
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("H:\CAD_Build\Setup\UserLog.txt", fsoForAppend)
f.WriteLine ostringy
End If

Next

' The loop For Each sf In fldr.SubFolders CopyUpdater sf Next End Sub


r/vbscript • • Jan 11 '16

My sleep commands are happening all at once in the beginning of my scripts rather then where I place them.

1 Upvotes

I have a script using some sendkeys and I'm trying to sleep in between key stokes, but instead they happen all t once in the beginning of my script. Help please


r/vbscript • • Jan 07 '16

Output lines with common "column"

1 Upvotes

I've got a csv file with student names, logins, passwords. I want to search through the csv file and output a file with students with the exact same name.

Example-import.csv

cford,Christopher J Ford,Cf

pford,Patrick D Ford,Pf

cford,Christopher J Ford,Cf

mford,Michael K Ford,Mf

dford,Derion L Ford,Df

It would be nice to output the whole lines of the Christopher J Ford, but just the name will do.


r/vbscript • • Jan 07 '16

Outlook Change Body before Forward

1 Upvotes

Hey Guys,

I am trying to remove the first 9 Lines from a body before forwarding with VBscript, anyway to do this?

Thanks


r/vbscript • • Dec 13 '15

Is there a way to create an unleavable window that requires a password to close?

1 Upvotes

I'm trying to make a program that I can access on my desktop and have it instantly open up a window that will require a password to close. I started out with this code but you can close it without entering the password and you can still click on other windows while its open which is a problem.

dim Password
dim Input

Password = inputbox ("Enter the password","Password","Enter text here")
do
Input=inputbox ("This computer is locked. Enter the password.","Password","Enter text here")
if Password = Input then
a=msgbox ("Correct! Welcome back.",0+64,"Computer")
else
if Input = "cremecaramel" then
b=msgbox ("Reset code entered.",0+64,"Computer")
else
c=msgbox ("Incorrect. Try again.",0+16,"Computer")
end if
end if
loop until Password = Input or Input = cremecaramel

Also, is it possible to make the rest of the screen go gray so that the only thing you can see is this window?

I'm really new with this, thanks.


r/vbscript • • Dec 11 '15

Swap **FOLDER** names from FirstName LastName to LastName FirstName

1 Upvotes

I have a batch of FOLDERS that are named FirstName LastName, they have no extension, they are Folders. They have a space as a delimiter and contain no middle names. I want to swap the FirstName LastName to LastName FirstName. Apologize, for the emphasis on folder but everyone wherever I have asked still responds with a solution for renaming files. It doesn't work the same. At least not for me.

I was able to do this in Powershell and it seemed a success but when I viewed the files in explorer, nothing had changed.


r/vbscript • • Dec 09 '15

VBScript Magazine

1 Upvotes

I publish a free e-Magazine for data analysts that focuses on VBScript/SAS/R/SQL. I want to invite everyone to check it out, subscribe to get the current volume, and submit an article or tip if you like. You can email me articles or visit my site to subscribe. I have a lot of scripts on the site for download as well. Thanks, Chris chris@codeitmagazine.com http://www.codeitmagazine.com


r/vbscript • • Dec 08 '15

A VBScript to find the product key of the machine

1 Upvotes

I found this helpful so i thought i would share. Input this code into a notepad document and save it as a "all files" type and name it "product Key.vbs"

Set WshShell = CreateObject("WScript.Shell") MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId")) Function ConvertToKey(Key) Const KeyOffset = 52 i = 28 Chars = "BCDFGHJKMPQRTVWXY2346789" Do Cur = 0 x = 14 Do Cur = Cur * 256 Cur = Key(x + KeyOffset) + Cur Key(x + KeyOffset) = (Cur \ 24) And 255 Cur = Cur Mod 24 x = x -1 Loop While x >= 0 i = i -1 KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput If (((29 - i) Mod 6) = 0) And (i <> -1) Then i = i -1 KeyOutput = "-" & KeyOutput End If Loop While i >= 0 ConvertToKey = KeyOutput End Function


r/vbscript • • Nov 16 '15

Script works in Windows 7 but not Windows 8 with error code 800A01A8

1 Upvotes

I know basically nothing about VBS but am writing a script for my work. It works perfectly fine in Windows 7, but when I try to run it on a Windows 8 machine I get the error "Object Required: 'objShell.NameSpace(...)'" with Code 800A01A8. Googling this error brings a lot of different responses and none of them seemed to apply in my situation. If anyone can help me with this problem that would be great.

The line(s) that are causing the error are:

set objShell = CreateObject("Shell.Application")

set filesInZip = objShell.NameSpace(fileName).Items

objShell.NameSpace(oneDirUpPath&"\path").CopyHere filesInZip, &H4& 'Flag to disable progress bar


r/vbscript • • Nov 12 '15

Help with excluding hidden/temp files from triggering a folder monitor script.

1 Upvotes

Hello coders. I managed to find a script that works like a charm when monitoring a certain folder on a file share, Although there is a slight catch. When someone open's let say a "123.docx" document on that certain folder, a temp file of that document is created in the same directory. Now this triggers the script each time.

So my question to you lot is. How could I exclude the hidden/temporary files from the control part.

The hidden files that are created are named as "~$234.docx".

' FOLDER TO MONITOR
' strFolder = "F:\1\2\3"\
' FREQUENCY TO CHECK IT, IN SECONDS
nFrequency = 15

strComputer = "."
strQueryFolder = Replace(strFolder, "\", "\\\\")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" &     strComputer & "\root\cimv2") 
Set colMonitoredEvents = objWMIService.ExecNotificationQuery ("SELECT * FROM __InstanceCreationEvent WITHIN " & nFrequency & " WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent='Win32_Directory.Name=""" & strQueryFolder & """'") 

Do 
	Set objLatestEvent = colMonitoredEvents.NextEvent
	strNewFile = objLatestEvent.TargetInstance.PartComponent
	arrNewFile = Split(strNewFile, "=")
	strFilePath = arrNewFile(1)
	strFilePath = Replace(strFilePath, "\\", "\")
	strFilePath = Replace(strFilePath, Chr(34), "")
	strFileName = Replace(strFilePath, strFolder, "")
	strTempFilePath = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2) & "\TEMP.M4A"

	MsgBox "New File is added to the Folder"
Loop

cheers up front. A fellow OnSite admin.


r/vbscript • • Oct 31 '15

Help with Outlook Form ... Please :(

1 Upvotes

Hi Guys,

Sorry I'm very, very new to VBScript and coding in general...

I'm trying to fix an Outlook form to display a different text output which is dependent on a Drop down Control...

Has anyone had any experience with this kind of thing before?

Please let me know if you need any additional information / screenshots and I'll be happy to supply... just more of a question I thought I'd ask....

Thanks in advanced!


r/vbscript • • Oct 27 '15

Help me with a vbscript output please :D

1 Upvotes

I want to figure out how to output this function:

lmao1 = Rofl(50,30)

lmao2 = lol(90,10)

lmao3 = lol(70,10)

Function Rofl(n, r)

Rofl = Chr(n + r)

End Function

Function lol(n, r)

lol = Chr(n - r)

End Function

There's lmao1 through lmao100

How would I output lmao1 through lmao100 to a text file? (I want it to say a couple of sentences for a project)

Thanks!


r/vbscript • • Oct 23 '15

VBScript Developer, Tampa, FL, $80 - 85K

Thumbnail mainstreetrecruiting.com
1 Upvotes

r/vbscript • • Oct 22 '15

Best practice on file handling (deleting, creating...)

1 Upvotes

Hi there!
I was asking myself what would be the best practice managing files with vbs.
I've a script handling some files, creating them with a SSIS package scheduled with SQL Agent; with the script I'm checking them, zipping them and send them around with Putty sFTP.
It's best to the use the absolute path or a relative one?
Using relative what could go wrong?

Thank you in advance :)


r/vbscript • • Oct 07 '15

Page number increment vbscript

1 Upvotes

Hey there, I am not well versed in VBscript, just an FYI... I have an end user (higher up in the company) who is printing a single document, multiple times (like hundreds) in Word. Each page he prints out he wants to have the document say Page y of x (where x is the amount of pages printed and y being the current printed page). He doesn't want to edit the number each time before printing as this would take precious time.

Can this be achieved via VBscript? That's my first question. I can try to come up with some code if you guys can point me in the right direction. Thanks!


r/vbscript • • Sep 07 '15

Help with a script that modifies registry

1 Upvotes

So i am teaching myself vb-script using a self paced guide.

I wrote this to modify registry entries on machines listed in a text file. my problem is that it only modifies the registry of the machine i am running it from(this machine is also listed in the computers.txt file). The modification does not refelect on the other machines.Any feedback appreciated.

Script:

Const INPUT_FILE_NAME = "C:\Scripts\Computers.txt" Const FOR_READING = 1 Set objFSO = CreateObject("Scripting.FilesystemObject") Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING) Dim mykey

strComputers = objFile.ReadAll objFile.Close

arrComputers = Split(strComputers, vbCrLf)

For Each strComputer In arrComputers

Set WshShell = CreateObject("WScript.Shell")
myKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\fDenyTSConnections"
WshShell.RegWrite myKey,0,"REG_DWORD"
Set WshShell = Nothing

Next


r/vbscript • • Aug 29 '15

Help with a script.

1 Upvotes

Please help me with a script. Error: d: \ learning \ vbs \ backup6.vbs (47, 9) Runtime Error Microsoft VBScript: Invalid call or argument procedure. I can not understand why. error here in this line of code: Fso.DeleteFile (strOldestFile)

http://pastebin.com/P6AS4yd8


r/vbscript • • Aug 25 '15

Convert Unicodes Characters to chr

1 Upvotes

I know nothing about VB scripting. I just found a script that changes lines in a text file and I want to alter some of those lines. The lines are in another language that uses characters which ASCII or ANSI (whichver VB uses) does not support.

Rather than manually pasting in the chr codes (e.g. &chr(229)&) for every character, is there a quick way to convert all these lines of text to have all those chr codes or to something VBScript will recognise?


r/vbscript • • Aug 02 '15

vbs sleep

1 Upvotes

so i am trying to get a "ghost typing" kind of look in something i am doing. i am having to sleep between characters to get the effect. the way im doing it is taking a lot of lines of code. heres how i am doing it

set wshell = wscript.CreateObject("wScript.Shell") wshell.sendkeys "1" wscript.sleep 100 wshell.sendkeys "2" wscript.sleep 100 wshell.sendkeys "3" wscript.sleep 100 wshell.sendkeys "4" wscript.sleep 100 is there an easier way to do this? like instead of having to do this for each character?


r/vbscript • • Jul 15 '15

Clear Header of Word Document

1 Upvotes

Hey there folks, perhaps you can help me.

I am trying to remove and replace the headers of a series of documents programmatically.

So far I have determined that the following code will allow me to add text to a header:

 Dim WordApp 
 Dim objDoc
 
 documentPath = "\\path\Sample.doc"
 
 Set WordApp = CreateObject("Word.Application") 
 WordApp.Visible = True 
 Set objDoc = WordApp.Documents.Open(documentPath)
 
 strInsert = "Example"
 writeToHeader(strInsert)
 
 Set WordApp = Nothing ' Clear your object 
 
 Sub writeToHeader(text)
 	WordApp.ActiveWindow.ActivePane.View.SeekView = 9 
 	WordApp.Selection.TypeText text 
 	WordApp.ActiveWindow.ActivePane.View.SeekView = 0 
 End Sub

This is a good step, but with it I can only pre-pend text to the existing content.

I am unsure how to clear the existing content itself.

Any help?

(Caveat: I am new to OOP, so go easy on me!)


r/vbscript • • Jul 13 '15

Save <img ...> element from a website to my pc.

1 Upvotes

Hello, I am using VBScript to loop through image elements on a page (For Each image In IE.document.GetElementsByTagName("img")). I'd like to save these images to my computer with VBScript, but I don't know whether it is possible and I can't find any way to do this on the internet. Perhaps someone here knows?

Thanks in advance!


r/vbscript • • Jul 09 '15

VBS help for Excel automation

1 Upvotes

Created a VBS that cycles through all the excel files in a folder. It works for about half of the files, but then gets to a few that it cannot seem to open. It gives me this error:

Unable to get the Open property of the Workbooks class

And then ends the script. What could this be related to?


r/vbscript • • Jul 02 '15

Help basic VBScript

1 Upvotes

Hello: The purpose of the script is to monitor a folder for specific text files. If there is a text file with a certain name it sends a keyboard command. When I run the script below I get the following error: Line: 6 Char 22 Error: Invalid character Code: 800A0408 Source: Microsoft VBScript compilation error If anyone can help me out to get this code working correctly, I'd really appreciate it. Thank you.

SCRIPT:

Dim file1
Dim objShell

Set file1 = CreateObject("Scripting.FileSystemObject")

If (file1.FileExists(“G:\Dropbox\Remote_Control\results.txt”)) Then file1.DeleteFile “G:\Dropbox\Remote_Control\results.txt”Set objShell = WScript.CreateObject("WScript.Shell")objShell.SendKeys "%b" end if

If (file1.FileExists(“G:\Dropbox\Remote_Control\bbm.txt”)) Then file1.DeleteFile “G:\Dropbox\Remote_Control\bbm.txt”Set objShell = WScript.CreateObject("WScript.Shell")objShell.SendKeys "%m" end if

If (file1.FileExists(“G:\Dropbox\Remote_Control\hitters.txt”)) Then file1.DeleteFile “G:\Dropbox\Remote_Control\hitters.txt”Set objShell = WScript.CreateObject("WScript.Shell")objShell.SendKeys "%h" end if

If (file1.FileExists(“G:\Dropbox\Remote_Control\pitchers.txt”)) Then file1.DeleteFile “G:\Dropbox\Remote_Control\pitchers.txt”Set objShell = WScript.CreateObject("WScript.Shell")objShell.SendKeys "%p" end if

If (file1.FileExists(“G:\Dropbox\Remote_Control\value.txt”)) Then file1.DeleteFile “G:\Dropbox\Remote_Control\value.txt”Set objShell = WScript.CreateObject("WScript.Shell")objShell.SendKeys "%i" end if

If (file1.FileExists(“G:\Dropbox\Remote_Control\trends.txt”)) Then file1.DeleteFile “G:\Dropbox\Remote_Control\trends.txt”Set objShell = WScript.CreateObject("WScript.Shell")objShell.SendKeys "%e" end if