VBA - Internet explorer automation + Export to excel via button/ javascript

carltheSwed

New Member
Joined
Feb 9, 2016
Messages
2
Hi,

What i want the VBA code to achieve:
1. Go to a specific internet explorer site (this is already working)
2. When at this site press a button (export to excel) (here i am stuck/ where it crashes :) )
3. Save the excelfile in a folder

Via Chrome i have been able to look into the html code and i believe what i need to to is to run the javascript function stated bellow:
"""""



MY VBA CODE SO FAR
(red is where i am stuck)

Code:
[/COLOR]Private Sub Populate_Click()
    Dim i As Long
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object


    Set IE = CreateObject("InternetExplorer.Application")


    IE.Visible = True
    IE.Navigate "webpage" 'make sure you've logged into the page


    Do
        DoEvents
    Loop Until IE.READYSTATE = 3
    
[COLOR=#ff0000][B]    IE.Document.parentWindow.execScript "dosubmitExcel();"[/B][/COLOR]
    
End Sub
[COLOR=#333333][Code]


Thanks a million![/COLOR]
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Thanks for the help but its not working.

Maybe it has something regarding when i go to the "webpage" (MR URL) i get redirected to another webpage. So whats happens:
1. Go to the page where my URL is set in the macro
2. Go to a second IE window (in a separate IE

I dont really now what "document"/parentWindow i am calling from.

I have tried to do the following (close down the first window and then run the next two steps in the macro)
IE.document.all.Item
Call IE.document.parentWindow.execScript("dosubmitExcel()", "JavaScript")

But that doesent work either :)
 
Upvote 0
Also, maybe you need to know which IE page you are on.

Code:
Const myPageTitle As String = "this is my webpage"
Set ObjIE = GetOpenIEByTitle(myPageTitle, False)
 
    If ObjIE Is Nothing Then
        MsgBox "No, webpage is present."
        Exit Sub
    End If



Code:
Function GetOpenIEByTitle(i_Title As String, _                          Optional ByVal i_ExactMatch As Boolean = True) As SHDocVw.InternetExplorer
Dim objShellWindows As New SHDocVw.ShellWindows


  If i_ExactMatch = False Then i_Title = i_Title & "*"
 Debug.Print i_ExactMatch
  'ignore errors when accessing the document property
  On Error Resume Next
  'loop over all Shell-Windows
  For Each GetOpenIEByTitle In objShellWindows
    'if the document is of type HTMLDocument, it is an IE window
    If TypeName(GetOpenIEByTitle.document) = "HTMLDocument" Then
      'check the title
      Debug.Print GetOpenIEByTitle.document.title
      If GetOpenIEByTitle.document.title Like i_Title Then
        MsgBox ("FOUND!")
        'leave, we found the right window
        Exit Function
      
      End If
    End If
  Next
End Function
 
Upvote 0

Forum statistics

Threads
1,216,129
Messages
6,129,055
Members
449,484
Latest member
khairianr

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