I need to type " into notepad with VBS script.
I have this code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad"
wscript.sleep 500
WshShell.sendkeys "some "text""
But it shows an error.
CodePudding user response:
You need to double up the quotes inside or you can use chr(34)
Text = "my ""example"" of doubled quotes"
Text = "use " & Chr(34) & "chr ()" & Chr(34) & " function"
CodePudding user response:
Set WshShell = WScript.CreateObject('WScript.Shell')
WshShell.Run 'notepad'
wscript.sleep 500
WshShell.sendkeys 'some "text"'
CodePudding user response:
Here is an exapmle showing you how to use the "double quotes"
and the 'simple quotes'
using a function :
Option Explicit
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "notepad"
wscript.sleep 1500
WshShell.sendkeys "some "& DblQuote("Text in Double Quotes") & vbcrlf &_
" another example : " & vbcrlf &_
SimpleQuote("Text between simple Quotes")
'--------------------------------------------------------------------------------
Function DblQuote(str) : DblQuote = chr(34) & str & chr(34) : End Function
'--------------------------------------------------------------------------------
Function SimpleQuote(Str) : SimpleQuote = ChrW(39) & Str & ChrW(39) : End Function
'--------------------------------------------------------------------------------