Prev: Send Key is not working for inactive windows
Next: AppActivate Fails for Windows Security Prompt
From: Anand on 26 Mar 2010 05:55 Hi, Really appreciate if you offer me a permanent or Alter net solution for my problem. I have screwed up with "send key" issue past couple of days. I am trying to convert a html file(which contains images) to mht file to make single archive file through below given script. But below script works if i directly run the script. The same script If i run through windows scheduler it won't work. Only it executes the file name it wont pass send key to executed file. +++++++++My Script+++++++++++++++++++++++ Dim Dir Dir = "c:\Report" set oShell = createobject("shell.application") set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run("c:\Report\Module.html") WshShell.AppActivate("c:\Report\Module.html - Microsoft Internet Explorer") WshShell.SendKeys "%f" WScript.Sleep 500 WshShell.SendKeys "a" WScript.Sleep 500 WshShell.SendKeys "c:\Report\Module.mht" WScript.Sleep 500 WshShell.SendKeys "{TAB}" WScript.Sleep 500 WshShell.SendKeys "w" WScript.Sleep 500 WshShell.Sendkeys "{Enter}" WScript.Sleep 500 WshShell.SendKeys "y" WScript.Sleep 500 WshShell.SendKeys "%{F4}" Highly appreciate if you offer me best automation solution through vb script. Tom Lavedas wrote: Re: AppActivate an Internet Explorer window 23-Jun-08 On Jun 20, 11:59=A0pm, mefi...(a)gmail.com wrote: {snip code} I find it hard to believe that the posted code did much, since there are a number of syntax problems in it. For what you say you want to do, this is more likely to work ... ---------------------8<---------------------- wsh.echo MatchWindows Function MatchWindows() Dim oShell, oWSHShell, sTitle, wndw, bMatch, IE sHTMLTitle =3D "Google" set oShell =3D createobject("shell.application") set oWSHShell =3D createobject("Wscript.shell") bMatch =3D false for each wndw in oShell.windows if instr(lcase(typename(wndw.document)), "htmldocument") > 0 then sTitle =3D wndw.document.title if Instr(sTitle, sHTMLTitle)<> 0 then bMatch =3D true exit for end if end if next if bMatch then oWSHShell.AppActivate sHTMLTitle oWSHShell.sendkeys "%{enter}" ' Restore if minimized else set oIE =3D CreateObject("InternetExplorer.Application") oIE.visible =3D true oIE.FullScreen =3D false oIE.Navigate "http://www.google.com" do until oIE.ReadyState =3D 4 : wsh.sleep 100 : loop oWSHShell.AppActivate sHTMLTitle end if Matchwindows =3D "Done, " & cStr(bMatch) end function ---------------------8<---------------------- Of course, you will want to remove the WSH.ECHO part to keep the focus on the Google window. I just put that in as a demonstration. Tom Lavedas =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Previous Posts In This Thread: On Saturday, June 21, 2008 10:20 AM mefirs wrote: AppActivate an Internet Explorer window I'm having some trouble accomplishing two tasks with a modified version of Tom Lavedas' script. Specifically, what I am trying to accomplish is: 1) Detect if any Internet Explorer windows are already open and that have a title of "Google - Windows Internet Explorer" 2) If there is, bring to the foreground (and with the focus) the first one found 3) If there are not, open up Internet Explorer and navigate to a specific web page (and with the focus) Tom Lavedas' script pretty much does the searching and title comparing, and that seems to work fine. My only issues is that I can't bring to foreground the windows (the one that I'm opening, and the one that already is open). Can anyone help me figure out what's wrong with my AppActivate ? Here is what I got so far: '-----------------< SNIP >------------------------- echo MatchWindows Function MatchWindows() Dim oShell, aHTMLTitles(), sTitle, wndw, bMatch, nCnt Dim IE sHTMLTitles = "Google - Windows Internet Explorer" nCnt = 0 set oShell = createobject("shell.application") for each wndw in oShell.windows if instr(lcase(typename(wndw.document)), "htmldocument") > 0 then sTitle = wndw.document.title bMatch = false for each entry in aHTMLTitles if entry = sTitle then sMatches = sMatches & vbNewline & vbTab & sTitle bMatch = true exit for end if next if not bMatch then Redim Preserve aHTMLTitles(nCnt) aHTMLTitles(nCnt) = sTitle nCnt = nCnt + 1 end if end if next if sMatches <> "" then oShell.AppActivate sHTMLTitles else set IE = CreateObject("InternetExplorer.Application") IE.visible = true IE.FullScreen = false IE.Navigate "http://www.google.com" SYS_objShell.AppActivate sHTMLTitles end if end function '-----------------< /SNIP >------------------------- On Monday, June 23, 2008 6:38 AM Tom Lavedas wrote: Re: AppActivate an Internet Explorer window On Jun 20, 11:59=A0pm, mefi...(a)gmail.com wrote: {snip code} I find it hard to believe that the posted code did much, since there are a number of syntax problems in it. For what you say you want to do, this is more likely to work ... ---------------------8<---------------------- wsh.echo MatchWindows Function MatchWindows() Dim oShell, oWSHShell, sTitle, wndw, bMatch, IE sHTMLTitle =3D "Google" set oShell =3D createobject("shell.application") set oWSHShell =3D createobject("Wscript.shell") bMatch =3D false for each wndw in oShell.windows if instr(lcase(typename(wndw.document)), "htmldocument") > 0 then sTitle =3D wndw.document.title if Instr(sTitle, sHTMLTitle)<> 0 then bMatch =3D true exit for end if end if next if bMatch then oWSHShell.AppActivate sHTMLTitle oWSHShell.sendkeys "%{enter}" ' Restore if minimized else set oIE =3D CreateObject("InternetExplorer.Application") oIE.visible =3D true oIE.FullScreen =3D false oIE.Navigate "http://www.google.com" do until oIE.ReadyState =3D 4 : wsh.sleep 100 : loop oWSHShell.AppActivate sHTMLTitle end if Matchwindows =3D "Done, " & cStr(bMatch) end function ---------------------8<---------------------- Of course, you will want to remove the WSH.ECHO part to keep the focus on the Google window. I just put that in as a demonstration. Tom Lavedas =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Submitted via EggHeadCafe - Software Developer Portal of Choice BizTalk Custom Pipeline for Splitting Messages http://www.eggheadcafe.com/tutorials/aspnet/a0786aaf-c159-40ff-9cf6-241d5e325f42/biztalk-custom-pipeline-f.aspx
|
Pages: 1 Prev: Send Key is not working for inactive windows Next: AppActivate Fails for Windows Security Prompt |