Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / August 2006



Tip: Looking for answers? Try searching our database.

Automating Internet Explorer with Excel VBA and JavaScript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
chris_j_adams@hotmail.com - 30 Aug 2006 18:57 GMT
Hi,

I'm trying to use Excel VBA ('97) to send details from an Excel sheet
to a web page.  I'm having some success but I've one issue that's
proved difficult to find in the archives.

There are a number of elements (ie. text boxes) on this web page that
are conditionally "greyed out".  They should become visible (ie. not
greyed) when a prior element is entered with data.  However, this is
not happening.  The elements are being filled, but they are not
becoming visible.

As a result, when I click the "Submit" button at the bottom of the
page, I get error messages saying these elements are required.  Data
has definitely been entered into these elements, but because the
elements do not become un-greyed, I suspect the data is not being
captured.

I viewed the source code and found what looks like a command associated
with these elements: onchange="rethinkChargeCurrency(1)".  This
suggests a variable, rethinkChargeCurrency(1) is being changed upon a
change in the element.  However, I could not find any further reference
to this variable.

I've not much knowledge of JavaScript and I wonder if I need to put a
check in my code to "enable" these fields?  Or do I need to change this
variable?

I've put an example skeleton of my code below. Hope it is sufficiently
illustrative.

Many thanks in advance for any help provided.

Regards,
Chris Adams

Sub startIexplore()

   Dim IeApp As InternetExplorer
   Dim i As Integer
   Dim nm as String

   'Open Web
   Set IeApp = New InternetExplorer
   IeApp.Visible = True
   IeApp.Navigate "http:\\WebAddressGoesHere.com"
   Do:     Loop Until IeApp.ReadyState = READYSTATE_COMPLETE

   With IeApp.Document.forms("form")
     ' Fill in names - these are the elements that need to be filled
in to un-grey the others
     For i = 0 To 4
        nm = "sources[" & i & "].name"
       .elements(nm).Value = "S" & i
     Next i

     ' Type - these are the elements that will be un-greyed, upon
completion of "names"
     For i = 0 To 4
       nm = "sources[" & i & "].type"
       .elements(nm).selectedIndex = 2
    Next i

   .submit         ' I get error messages on the following pages,
saying the "types are required"

   End With

IeApp.Quit

End Sub

(I've made an assumption that cross-posting is acceptable in this case,
sorry if not).
chris_j_adams@hotmail.com - 31 Aug 2006 08:59 GMT
The following solution was posted in the
microsoft.public.excel.programming newsgroup.
It worked, although I had to be selective with which elements I
included the statement (not sure why, I'll try to work the reason out
for this later).

Regards,
Chris Adams

chris_j_ad...@hotmail.com wrote:
>     With IeApp.Document.forms("form")
>       ' Fill in names - these are the elements that need to be filled in to un-grey the others
>       For i = 0 To 4
>          nm = "sources[" & i & "].name"
>         .elements(nm).Value = "S" & i

Try whether doing
     .elements(nm).onchange
here helps.

--

       Martin Honnen --- MVP XML
       http://JavaScript.FAQTs.com/

> Hi,
>
[quoted text clipped - 70 lines]
> (I've made an assumption that cross-posting is acceptable in this case,
> sorry if not).
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.