Jump to content
Macro Express Forums

IE connectivity through External Script


Recommended Posts

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...