gagangoomer Posted September 13, 2013 Report Share Posted September 13, 2013 Hi, I'm trying to connect MEP to IE through External Script option. Below is the code to activate IE window. I've run this code in VBA and is working fine but the same code when i put under MEP under External Script option it doesn't works. Dim btnSelectList As MSHTML.HTMLSelectElement Dim btnOptionList As MSHTML.HTMLOptionElement, ElementColList As MSHTML.IHTMLElementCollection Dim ElementCol1List As MSHTML.IHTMLElementCollection, i As Long, j As Long, URL As String Dim ie As InternetExplorer Set ie = New InternetExplorer Set ie = CreateObject("internetexplorer.application") ' Create IE object ie.Visible = True ie.navigate http://google.com 'Open URL Do Until ie.readyState = READYSTATE_COMPLETE 'Wait till the page gets loaded in the browser Loop Can anyone help on this ? Quote Link to comment Share on other sites More sharing options...
Cory Posted September 13, 2013 Report Share Posted September 13, 2013 I don't have time at the moment but reflexively I'm guessing it's because it's VBA. VBA and VBScript are very similar in many ways but not wholly interchangeable. Infrequently I need to adapt from VB, VBA, and VBS and it always requires tweaking. I suggest you save this script to a VBS file and execute it from a command prompt and get the script working there where the interpreter can return error codes. Quote Link to comment Share on other sites More sharing options...
gagangoomer Posted September 13, 2013 Author Report Share Posted September 13, 2013 Thanks for Replying Cory. I tried the option you suggested by calling the.vbs file in my macro but it doesn't works. That's why i used the External script option in my code. Also i'm not aware of how to use then .vbs file in a command prompt. Would you like to share any example file for .vbs file which works with cmd. Do we need to establish connection or something to work on cmd ? Quote Link to comment Share on other sites More sharing options...
paul Posted September 14, 2013 Report Share Posted September 14, 2013 Also i'm not aware of how to use then .vbs file in a command prompt. Open a command prompt window, and type the name of your script, uncluding the pathname if required, AND the extension, e.g. d:\mypath\myscript.vbs Quote Link to comment Share on other sites More sharing options...
Cory Posted September 17, 2013 Report Share Posted September 17, 2013 Paul is correct. Get it running as a VBScript first. I just tried it and it failed on line 1. I'm guessing because you are not importing the namespace but I don't have time to troubleshoot your code for free:-) Like I said it's syntactically different. For instance this VBS will open IE and navigate to my webpage. See the subtle differences? Just save that to a text file named test.vbs or whatever you like and double click it. Set objBrowser = CreateObject("InternetExplorer.Application") objBrowser.Visible = 1 objBrowser.Navigate "http://bluepointdesign.com" It appears you're trying to automate a web browser session. I don't know what you're trying to accomplish but I do this sort of thing all the time for clients, mainly building scrapers. It was simply too frustrating to do reliably for large batches in MEP so I learned VB.NET and now build WinForm applications to do this. If you would like some professional help please let me know. Quote Link to comment Share on other sites More sharing options...
gagangoomer Posted September 19, 2013 Author Report Share Posted September 19, 2013 Paul, I tried to run the .vbs file from CMD. Does it simply opens the .vbs file from the particular location or does it runs the file. In my case it just opened the file. Quote Link to comment Share on other sites More sharing options...
paul Posted September 19, 2013 Report Share Posted September 19, 2013 Paul, I tried to run the .vbs file from CMD. Does it simply opens the .vbs file from the particular location or does it runs the file. In my case it just opened the file. Presumably you mean the file opened in Notepad? If so, you'll need to change the .vbs extension's association in the registry, so that it runs instead of "opening". Quote Link to comment Share on other sites More sharing options...
gagangoomer Posted September 20, 2013 Author Report Share Posted September 20, 2013 Yes, it opens with Notepad. I'm not sure how to runs it instead of opening it. Though i tried to find out the option under Folder Option --> File types and change the Open with Option. But Didn't get any success. Can you please guide me through how to Run it inseated opening it. Quote Link to comment Share on other sites More sharing options...
paul Posted September 23, 2013 Report Share Posted September 23, 2013 The location of the program you'll need is C:\Windows\System[32]\wscript.exe Quote Link to comment Share on other sites More sharing options...
Cory Posted September 23, 2013 Report Share Posted September 23, 2013 Just double click on it or use the run command with Win+R. Unless you have changed the file extension association it will open with WScript by default. Quote Link to comment Share on other sites More sharing options...
gagangoomer Posted September 24, 2013 Author Report Share Posted September 24, 2013 On double clicking this it simply opens up a box "Window Script Host Settings". I changed the settings Folder Option --> File types to open .vbs file with wscript.exe but still nothing happens. Any suggestions ? Quote Link to comment Share on other sites More sharing options...
Cory Posted September 24, 2013 Report Share Posted September 24, 2013 Seems like you have something messed up on your settings. Perhaps miss associated the file. If I were you I would Google "restore VBS file association". A quick search revealed some promising leads. However if I run WScript itself I get the "Windows Script Host Settings". Are you sure you're not running WScript.exe instead of the script file itself? If you're not then you're probably missing the variable that conveys the file name when you launch it from Windows File Explorer. Here's how it works. WScript is the host script interpreter. Think of it like Word.exe itself. And just the same she you associate the .DOC extension with Word so when you launch a Word document it opens that document in word. It's the same with .VBS files on a normal machine. You should be able to double click on a .VBS file and cause the OS to launch WScript.exe and pass to it the file name you want it to execute. But like Paul said just run WScript directly. I doubt you need the whole path to WScript but do this test just to be certain. Open a Command Prompt and type "WScript.exe /?" and hit enter. If the help for WScript pops up then you don't need the whole path as it resides in one of the search paths. Also you can try typing just "Wscript /?" as the .EXE should not be needed. Assuming this is the case now simply type WScript and your script EG "wscript c:\MyTestScript.vbs" at the command prompt. http://forums.vandyke.com/showthread.php?t=1074 You might also check out the first response here for installing and using the WScript debugger and using the //X option. I've not done it before but it sounds like it might be able to help you more. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.