Saving snapshot using vbscript
This won't work. Microsoft Word is in focus while the Print Screen button is pressed. You can easily eliminate this problem by not using Microsoft Word at all. It's not necessary. The Print Screen function is a system hotkey and has nothing to do with Microsoft Word. You should be using the Alt+PrintScreen combination which captures a screenshot of the currently focused window to the clipboard.
Second, if Paint is not in focus instead of IE, it's because you have the window title wrong. You are doing that part correctly. AppActivate returns false if it cannot find a window with the specified title. To be honest, Paint should alread have focus to begin with but it is good practice 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?
codeomnitrix
Young | Enthusiastic | Ecstatic | Raw Programmer | Counter-Strike
Updated on June 04, 2022Comments
-
codeomnitrix almost 2 years
I am new to vbscript. I want to save a snapshot taken using vbscript of a internet explorer 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"
Code to take snapshot
Dim oWordBasic set oWordBasic = CreateObject("Word.Basic") oWordBasic.sendkeys "{prtsc}" oWordBasic.AppClose "Microsoft Word" Set oWordBasic = Nothing Wscript.Sleep 2000
Saving the 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
Actually the previously opened ie window is having focus and the keystrokes are sent to the ie instead of paint. so is there any function which performs opposite work of
AppActivate
. -
codeomnitrix about 12 yearsHi Nilpo, Thanks for your response... but could you please tell me what wiil be proper title to be passed in the
AppActivate
so that the application can be on foreground... -
Nilpo about 12 yearsIt's different for each version of Windows. You'll need to open MS Paint and look at the title bar.
-
codeomnitrix about 12 yearsActually i am using windows 7 and the title bar is showing 'Untitled-Paint' for mspaint and that's what i am trying.
-
Nilpo about 12 yearsThere are usually space in between the words... "Untitled - Paint"
-
peter about 12 yearsHad the same problem, about the Word.Basic, i had to use this also because the Printscreen can not be used as a sendkey in Vbscript but it can in Word.Basic, it's the only reason i still use it
-
Nilpo about 12 yearsYou don't need to do that. Using
SendKeys "(%{1068})"
in VBScript works.