Bypass Save As Prompt when using ExecWB

keen1598

New Member
Joined
Apr 2, 2013
Messages
16
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
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,214,982
Messages
6,122,581
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top