简体   繁体   中英

How to use VBScript to open notepad and paste current date in it?

How to use VBScript to open notepad and paste current date in it?

This is all I have for now:

Set WshShell = WScript.CreateObject("WScript.Shell")
Call WshShell.Run("%windir%\system32\notepad.exe")
Dim aDate
aDate = Date()
WScript.Sleep 2000

Now, how do I paste the date?

Use SendKeys to send keystrokes to the active window.

Usage:

WshShell.SendKeys aDate

You may need to ensure that the focus is in the window you want to send keystrokes to. For this, use AppActivate method.

Using window title in this case:

WshShell.AppActivate "Untitled - Notepad"

你也可以使用

WshShell.SendKeys "{F5}"

I know i am late, but try the following code, it works:

Set wshshell = wscript.CreateObject("WScript.Shell")
Wshshell.run "Notepad"
wscript.sleep 100
dim aDate
aDate = Date()
wscript.sleep 2000
wshshell.sendkeys aDate
wscript.sleep 1000

Make sure the extension of the file is ".vbs"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM