user2917384
user2917384

Reputation: 1

Use Sendkeys to write variables into file

I am trying to use vbs to capture an ID inside an input box and then have that entered into the opened file. I've only learned how to write vbs script for this specific project, so what is written below is probably not kosher. I'm also not sure if using Sendkeys is the way to go, mostly because it hasn't worked yet. Thanks for any pointers.

Dim wshShell, ID

ID=inputBox("Please Enter the ID")

CreateObject("WScript.Shell").Run("file.sps")
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Sendkeys  "[the ID from above should go here]"
WshShell.Sendkeys "{Enter}"

Upvotes: 0

Views: 988

Answers (1)

Jobbo
Jobbo

Reputation: 1398

Avoid SendKeys like the plague.. its rarely the best way to do something. You just need to use the FileSystem Object:

Option Explicit

Dim fso,file
Dim id

id = inputBox("Please Enter the ID")
Set fso = CreateObject("Scripting.FilesystemObject")

'open the file for appending (8) create it if it doesn't exist
Set file = fso.OpenTextFile("file.sps",8,True)

Call file.writeLine(id)
Call file.close

Set file = Nothing
Set fso = Nothing
WScript.Quit

Upvotes: 2

Related Questions