Selecting checkboxes/radio buttons when controlling IE with VB

01-17-2006, 09:57 AM
Hi, I'm using VB to navigate IE in order to cut out a very tedious task. I'm almost there and can press buttons and enter text into text boxes but am having trouble checking boxes and radio selections.

A sample of the section of my current code that does the 'clicking around' (with thanks to NateO for that!)........

With ie.document.forms(0)
.All("years").Value = "2003"
.All("years").Value = "2001"
.All("years").Value = "2002"
.advanced.Value = "more text"
End With

The HTML of the radioboxes that are sending me crazy is

<input type="radio" name="Period" value="Year Selection">
<select name="years" size="1" class="" onChange="select_year_button('1');" onFocus="select_year_button('1');">
<option value="2006" selected>2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
etc. etc.

Other radio boxes have name="Period" but they have different strings as 'value' i.e. value="Year Range" (rather than "Year Selection" above).

I have tried the following combinations to control the radio boxes, but to no avail.

.All("Period").Value = "Year Selection"
.Period.Value = "Year Selection"

Pleeeeaaaaaase can someone tell me the correct way to chek the box????

Thanks in advance for your assistance.


01-17-2006, 02:37 PM
Dim ie As InternetExplorer
Dim d As HTMLDocument
Dim f As Object 'group of inputelements
Dim e As HTMLInputElement

Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "C:\aaa\temp\form.html"
Set d = ie.Document
Set f = d.all("Period")
For Each e In f
If e.Value = "Year Selection" Then
e.Checked = True
Exit For
End If
Next e

01-18-2006, 06:56 AM
Thanks herilane, that worked a treat!

Cheers for the tip!


01-18-2006, 09:12 AM
Hmmmm, with greatly appreciated help from NateO and herilane I have managed to navigate IE through a complicated series of webpages, but before I can loop back and re-fill-out the forms with different data, I have to deal with the File Download dialogue box (and then the 'Save As' box)

Does anyone have experience of these?

I need to press enter on (select) the 'Save As' button and then type a filename in the Save As dialogue box, followed by another 'return'.

I have tried using Sendkeys but I seemed to be getting problems making the window wait for the commands. I'm sure that there is a more elegant method. I have managed to avoid using Sendkeys so far in favour of ie.document.Form(0).blahblah commands. Can I use something similar to control the Save As box?

All help gladly received!



01-18-2006, 02:49 PM
Hmm... that's harder. I can't think of anything off-hand.
Could you post a link to the form you're working with, perhaps?

01-19-2006, 04:57 AM
Hmm... that's harder. I can't think of anything off-hand.
Could you post a link to the form you're working with, perhaps?

It's a subscribe site, so you probably wouldn't have access. The window that fires up the Save As box does so using some Jscript at the end of the HTML....

<script language="JavaScript">setTimeout("document.location = \"uml_view.cgi?product=WOS& lMgbE8NAb5jBmI%26Func%3DGoBack%26tFunc%3DFrmUML&product_sid=T1hkOlMgbE8NAb5jBmI& 2Fxrpc%2FStThomas&plugin=&fn=temp_upload%2FWOS_T1hkOlMgbE8NAb5jBmI.txt&save_file.x=0&save_file.y=0&file_opt=Tab%20Delimited%20(Windows)&\";",1000);</script>

It is this dialogue box that I have been trying to control.

Also there is a button on screen that fires up the same box using a href link rather than Jscript

It looks like there is info about a temporary text file (which is what I'm after) in that CGI string, but I don't know enough about that to work out whether I could get that directly somehow? If I could disable Jscript to stop the Save As firing up initially and then get the text file through non-Save dialogue box means, I might be getting somewhere.....but that might just be a desperate man talking!

If not, there must be a way to manoeuvre around the Save As box, it's just another part of IE after all. But then I suppose that if the facility has not been built in then there's not much you can do.......



01-20-2006, 09:41 AM
Hi Paul,

So, your JavaScript looks like it's pointing to a resulting url, which then downloads the file. Do you know if this is true? What is the resulting url once you hit yes?

The reason I ask, is that I've avoided popups in the past by hacking my way into the resulting Url.

If you use or have used Hotmail, do you know when you hit the 'Empty the JunkMail' button and you get the 'Are You Sure?' popup? Well, instead of doing this, I hacked to the resulting URL that happens once you say yes, this way, you never get the popup.

Here's my original source:

Private Sub DelJunkhotMail()
'Hotmail url constant
Const url As String = ""
Dim ie As Object, myurl As String, sngSt As Date, pLc As Integer
Dim myInbox As String

Select Case _
MsgBox("You are about to clear your Junk Folder," & _
"this data is not backed up." & Application.Rept(Chr(10), 2) & _
"Shall we proceed?" & Application.Rept(Chr(10), 2) & _
"If not, try the normal login variety.", vbYesNo)
Case vbNo
Exit Sub
End Select
On Error Goto 1
Set ie = CreateObject("InternetExplorer.Application")
With ie
.navigate url
Do While .ReadyState <> 4: Loop
'//Send data to IE
With .Document.passwordform
.login.Value = y & ""
.passwd.Value = z
.enter.Click 'Click the Submit button on the site.
End With
Do While .busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
'Wait Until you get to "Your Hotmail Home"
sngSt = Now
Do While InStr(.Document.url, "hmhome") = 0
'Colo sapiently tests for time
If Now - sngSt > TimeValue("00:01:00") Then GoTo 2
myurl = .Document.url
'hack url from "Home" To "Inbox"
myInbox = Application.Substitute(myurl, "hmhome", "HoTMail")
'Find the last digit of folder number
pLc = InStr(.Document.url, "hmhome") + Len("hmhome?curmbox=F00000000")
'Goto Junk Mail folder & call Hotmail's delete folder function
.navigate Application.Substitute(Mid(myurl, 1, pLc - 1), _
"hmhome", "HoTMail") & _
5 & Mid(myurl, pLc + 1, Len(myurl)) & "&DoEmpty=1"
Do While .busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
'Go back to the inbox
.navigate myInbox
Do While .busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
2: 'Let's maximize this puppy
Call ShowWindow(.hwnd, 3)
.Visible = True
End With

Set ie = Nothing
Exit Sub
1: MsgBox "Unexpected Error, sorry."
Set ie = Nothing
End Sub

The part where I hack to the url to avoid the popup and just empty the Junk folder is here:

'Goto Junk Mail folder & call Hotmail's delete folder function
.navigate Application.Substitute(Mid(myurl, 1, pLc - 1), _
"hmhome", "HoTMail") & _
5 & Mid(myurl, pLc + 1, Len(myurl)) & "&DoEmpty=1"
This was written with Excel, so don't use Excel's Substitute() or Rept() functions. Replace() and String() should work just fine. ;)

Also, do not even bother testing this code. I wrote it in 2003 or something, and two weeks after I wrote it, Microsoft changed all of the forms, controls and urls within Hotmail. It has no chance of working these days.

But, that's the concept that I was successful with. Perhaps you could run with something similar? :)

N. Paul Oliver

01-20-2006, 11:03 AM
Another thought might be to navigate on the JavaScript directly, e.g.,

The JS navigation script you want to focus on is this:

.navigate "JavaScript:if (fnValidate()) document.HorseSearchForm.submit();"
Not sure, but give it a go. The trick, I believe is to avoid navigating to the popup... That one was written just the other day, it should still be functional. ;)

01-25-2006, 09:19 AM
Hi Nate,

Yup, the JavaScript points to a URL which is a CGI string. The URL in the browser while all this is happening is "" and the JavaScript navigates to

product_sid=X117oapm3iifmFPDlBI& 2Fxrpc%

Which holds all of the options required to produce my data file (a tick down timer then counts on the page until the file is 'ready') and causes the dialogue box to appear asking me if I want to save or not (which I do!).

If I paste
into the browser, (unsurprisingly) the save as box appears.

I'm afraid I'm not quite sure how the code you posted would help (I don't quite understand it, so bear with me ;) ). Your code avoids a popup, but if I stopped the Save As box appearing, how would I get to my file? (maybe obvious, sorry if it is!).

I notice that the CGI string has a .txt file (which is what I'm after) in there somewhere....although the filename is different once the Save As box appears.

I didn’t quite understand your second suggestion as it involved calling JavaScript, which I have no real experience of.

Does any of this new information help? (Other than helping to determine the low level of my VBA understanding!)

Cheers in advance,


01-25-2006, 10:01 AM
Hi Paul,

Does any of this new information help? (Other than helping to determine the low level of my VBA understanding!)
Well, apparently not.

Ok, what do I mean by avoiding the Popup? You want to bypass it, if you can, similar to how I want to drive around Detroit when I want to get to the other side, because going through it doesn't work as well for me. ;)

You don't want to pass the url that generates the popup, you might be able to pass the url the follows the popup.

Let's take the following example:

Sub foo()
Select Case MsgBox("Click away", vbYesNo, "Hi")
Case vbYes
Call bar
Case vbNo
Call nadda
End Select
End Sub

Sub bar()
MsgBox "Someone clicked yes."
End Sub

Sub nadda()
End Sub
Our goal is to get to bar(), we don't care about foo() or the popup, we just want to download, so don't call foo(), call bar() directly.

So, the question is, what is your popup calling/doing? Remember, I can't see your popup (right?), so you'll need to figure out what happens following your click.

If you can hack to the result of the popup, perhaps you can avoid it.

That's what my Hotmail code did, it navigated to the url that resulted from someone hitting 'Yes' to empty their Junkmail. This navigation in turn called some Java to empty to folder.

Clear as mud? :)

01-27-2006, 08:02 AM
Ah, I see what you mean. The problem I have is that the displayed URL stays the same before during and after the Save Box appears.

I know what URL the Javascript is sending to make the Save As box appear, but this is a CGI string that sets a program running server-side so I can't see what URL this program is getting my download file from, hence I cant navigate there manually. :mad:

Ergh! If I knew more about CGI, I might be able to figure out what is going on.

01-28-2006, 01:06 PM
Are you sure it's not doing something temporarily? :confused:

I can't seem to recall what happened when I hacked the Hotmail "Junk Mail", long time ago... I do know that you still ended up in your Junk Mail folder, i.e., you weren't really navigating to a new location.

Try not to over think this CGI business, you're shooting yourself in the head (figuratively speaking) before you even start. Not good if success is one of your goals... There's got to be a way to see where that file's coming from, one way or another....

What have you tried? Sounds like you follow the concept, but I have yet to see any implementation.

01-30-2006, 08:31 AM
Hey Nate,

Well, I've looked in my history (on IE and FireFox) after downloading a file and
have no entry with a .txt extension, so I can't work out the temp storage
location of the file that way. With FF I can get the download file location from
the download 'properties'.....this gives me the CGI URL that the Javascript calls.... Jg68Hf6dhnm5%26Func%3DGoBack%26tFunc%3DFrmUML&product_sid=V2CaKPhJg68Hf6dhnm5& rpc%2FStThomas&plugin=&fn=temp_upload%2FWOS_V2CaKPhJg68Hf6dhnm5.txt&save_file.x=0&save_file.y=0&file_opt=Tab%20Delimited%20(Windows)&)

I've tried taking temp_upload%2FWOS_V2CaKPhJg68Hf6dhnm5.txt from the
URL and using different combinations on and

The '%2F' is equivalent of a '/', I think?!?

Also I have tried using this from the long CGI URL above....

as the root directory (subbing %3A for : and %2F for /) with
temp_upload/WOS_V2CaKPhJg68Hf6dhnm5.txt spliced on the end

There are a few '%2F's (i.e. '/'s -> directories) involved in that URL and I have
tried just the root, and with some/all the
sub-directories added.

The actual file that downloads is called savedrecs. txt and I have tried using
this as well as WOS_V2CaKPhJg68Hf6dhnm5.txt as the filename.

The only way that I can get at the file is by putting in the full URL that the
Javascript calls.

Argh.......... :(

01-30-2006, 03:55 PM

Is it possible for me to download this file? If so, can you explain how I could do this, manually?

This is a bit of a guessing game on my end at this point. :confused:

02-10-2006, 07:59 AM
Hey Nate,

The page I am looking at is part of the Web of Knowledge. Do you have access to that?


02-10-2006, 08:21 AM
That's a negative, Ghost-Rider; I'm afraid that pattern is full.

Sorry. :-\

02-16-2006, 06:35 AM
That's a negative, Ghost-Rider; I'm afraid that pattern is full.

Sorry. :-\

Hi Nate,

Still there? I got a tip re. downloading the file.

If I use x = DownloadFile( {whole CGI string here}, "c:\whatever.txt")

I can get to the download file.

Now all I need to do is stop the Save As box from ever appearing.

I have been trying to use the FileDownload event:

Private Sub ie_FileDownload(Cancel As Boolean)
Cancel = True
End Sub

Replacing 'Dim ie As InternetExplorer' within my sub with 'Public WithEvents ie As InternetExplorer' outside of my main sub.

But this seems to stop me performing some navigation tasks

specifically, pasting text into a text box (called "advanced") using:

ie.Document.forms(0).advanced.Value = srchstr

causes this error:

Object doesn’t support this property or method.

Arrghhhh! Just when I thought I was almost there! :(

Any ideas greatly appreciated!


02-16-2006, 09:45 AM
Hi Paul,

Yes, still here. :)

I have been trying to use the FileDownload event:
This is where it might be easier to use the 'Microsoft Web Browser' Control on a Form. The same to automate but I think it might be easier to handle events, e.g.,

Private Sub WebBrowser1_FileDownload(Cancel As Boolean)

End Sub
However, as I've never really used this (I've always automated IE), I should drop out of this thread, at this point. But, give it a whirl. :)

I'm not sure you have the right event, you might want to check out the following, as well:

02-16-2006, 10:08 AM
Thanks Nate! I'll have a read.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum