Saving a snapshot using vbscript

I am new to vbscript. I want to save the vbscript snapshot of an internet browser window opened by vbscript.

Code to load the page

Dim IE, stateString
Set IE = WScript.CreateObject("InternetExplorer.Application")
ie.toolbar = 1
ie.statusbar = 1
ie.width = 999
ie.height = 500
ie.left = 20
ie.theatermode = false
ie.theatermode = true
ie.theatermode = false
ie.top = 50
ie.navigate("file:///C:\Users\Vinit_Tiwari\Documents\vbscripts\someform.html")
'stateString = cstr(ie.readystate)
waitforload(ie)


ie.visible = 1

Set wshShell = CreateObject("Wscript.Shell")

wshShell.AppActivate "Some Form"
wshShell.SendKeys "% x"

      

Snapshot code

Dim oWordBasic
set oWordBasic = CreateObject("Word.Basic")
oWordBasic.sendkeys "{prtsc}"
oWordBasic.AppClose "Microsoft Word"
Set oWordBasic = Nothing
Wscript.Sleep 2000

      

Saving a Snapshot

dim paint
set paint = wshShell.exec("mspaint")
do while paint.status = 0:loop
wshShell.appactivate("untitled-Paint")'this returns false
Wscript.sleep 500
WshShell.SendKeys "^v"
wscript.sleep 500
wshshell.sendkeys "^s"
wscript.sleep 500
wshshell.sendkeys "d:\test.png"
wscript.sleep 500
wshell.sendkeys "{Enter}"
Set wshshell = Nothing

      

In fact, the previously open i.e. window has focus, and keystrokes are sent to the same and not to the paint. so there is some function that does the opposite job AppActivate

.

+3


source to share


1 answer


It won't work. Microsoft Word has focus while the Print Screen button is pressed. You can easily fix this problem without using Microsoft Word at all. It is not necessary. The Print Screen function is a system hotkey and has nothing to do with Microsoft Word. You must use the Alt + PrintScreen combination, which captures a screenshot of the currently focused window to the clipboard.

Second, if Paint is out of focus instead of IE, it is due to the wrong window title. You are doing this part right. AppActivate returns false if it cannot find the window with the specified title. To be fair, Paint needs to be focused to start, but it's best to make sure the window is activated first.



Also, is this a very old system? Why are you using the Word.Basic automation object anyway out of curiosity?

+2


source







All Articles