So I have this piece of code I've put together to access a website that was created to run reports. The website has some drop downs to select value for a report query and a button to run the report. The code then sets the value to two combo-boxes and clicks a button to query the database. If I knew the location of the database I would not be using this method, but as I do not and as the original creator of the DB no longer works with me, I don't know where the data is being stored to access it directly using ODBC. Instead im automating through IE automation. I get the values of the drop downs set and the button clicked, the problem is IE then prompts me to save or open the file. I've tried using ExecWB to bypass the saveas, set the directory of the file to be saved, as well as the file name, but I run into some problems. The saveas prompt still shows up, and the directory doesn't seem to get set to the location I specify. Here's my code. The function is supposed to run the report for the current month, the month before, and the month after, and save all of the files to the location I specified.
Code:
Sub GetIE()
' Dim shellWins As ShellWindows
Dim IE As InternetExplorer
Dim Element As IHTMLElement
Dim HTMLDoc As HTMLDocument
Dim startmonth As String
Dim varray As Variant
Dim saveme As String
Dim myfldr As String
myfldr = "some location"
startmonth = Format((Month(Date) - 1), "00")
saveme = "somename " & startmonth & "_" & Format((Year(Date)), "0000")
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate "http://old-hr-info.cfm"
IE.Silent = True
Do
Loop Until IE.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = IE.Document
For x = 0 To 2
For Each Element In HTMLDoc.getElementsByTagName("select")
If Element.Name = "month" Then
Element.Value = startmonth
End If
If Element.Name = "year" Then
Element.Value = Format((Year(Date)), "0000")
End If
Next Element
For Each Element In HTMLDoc.getElementsByTagName("button")
If Element.Name = "submit" Then
Element.Click
Application.Wait (Now() + CDate("00:00:02"))
saveme = "somename " & startmonth & "_" & Format((Year(Date)), "0000")
IE.ExecWB 4, 1, myfldr & saveme
Application.Wait (Now() + CDate("00:00:02"))' added for the sake of the sendkey
SendKeys ("{ENTER}") ' added to try and press the save button manually even though directory is still wrong
startmonth = startmonth + 1
End If
Do
Loop Until IE.ReadyState = READYSTATE_COMPLETE
Next Element
Next x
Set shellWins = Nothing
Set IE = Nothing
Exit Sub
Err_Clear:
If Err <> 0 Then
Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub