2017-08-31 1 views
0

まずはプログラマーではなく、Excelに入力データを入れてhttps://www.nseindia.com/products/content/equities/equities/eq_security.htmから見積もり履歴をダウンロードしたいだけです。私は何とかVBAにデータを置くことができました。誰でも "CSV形式のファイルをダウンロード" &をローカルディスクに保存する方法を教えてください。 UDF以下NSEインド見積もり履歴自動ダウンロード

Private Sub CommandButton1_Click() 
    Dim IE As Object 
    With IE 
    Set IE = CreateObject("InternetExplorer.Application") 

'create new instance of IE. use reference to return current open IE if 
'you want to use open IE window. Easiest way I know of is via title bar. 
    IE.Navigate "https://www.nseindia.com/products/content/equities/equities/eq_security.htm" 
'go to web page listed inside quotes 
    IE.Visible = True 
    While IE.busy 
    DoEvents 'wait until IE is done loading page. 
    Wend 
    IE.document.ALL("symbol").Value = ThisWorkbook.Sheets("sheet1").Range("b1") 
    IE.document.ALL("series").Value = ThisWorkbook.Sheets("sheet1").Range("b2") 

    IE.document.getElementById("rdDateToDate").Click 

    IE.document.ALL("fromDate").Value = ThisWorkbook.Sheets("sheet1").Range("b4") 

    IE.document.ALL("toDate").Value = ThisWorkbook.Sheets("sheet1").Range("c4") 
    IE.document.getElementById("submitMe").Click 

    End With 

End Sub 
+0

あるものは何でもへのセル参照は、あなたは 'Symbol'と' Series'に値を提供することができます?あなたの 'From Date'と' To Date'も理想的ですが、それらは重要ではありません – Zac

+0

シンボル= SBIN、シリーズ= EQ、日付= 01-01-2012&To Date = 01-12-2012 –

+0

そしてコードを入力してくださいIEを自動的に閉じます。ありがとうございました。 –

答えて

0

あなたが探しているものを行います:ここで

は私のVBAコードがある

Private Sub CommandButton1_Click() 
    Dim IE As New InternetExplorer 
    Dim oW As Worksheet: Set oW = ThisWorkbook.Worksheets("Sheet4") 
    Dim oEleCol As MSHTML.IHTMLElementCollection 
    Dim oEle As MSHTML.IHTMLElement 


    With IE 
    'Set IE = CreateObject("InternetExplorer.Application") 

     ' Set IE 
     .Visible = True 
     'ShowWindow .hwnd, SW_SHOWMAXIMIZED 

     ' Navigate to URL 
     .Navigate "https://www.nseindia.com/products/content/equities/equities/eq_security.htm" 

     ' Wait for page to be ready 
     While .Busy 
      DoEvents 'wait until IE is done loading page. 
     Wend 

     ' Set criteria 
     .document.all("symbol").Value = oW.Range("I2") 
     .document.all("series").Value = oW.Range("I3") 
     .document.getElementById("rdDateToDate").Click 

     ' Wait for page to be ready 
     While .Busy 
      DoEvents 'wait until IE is done loading page. 
     Wend 

     ' Set remaining criteria 
     .document.all("fromDate").Value = oW.Range("I4") 
     .document.all("toDate").Value = oW.Range("I5") 

     ' Submit criteria 
     .document.getElementById("submitMe").Click 

     ' Wait for page to be ready 
     While .Busy 
      DoEvents 'wait until IE is done loading page. 
     Wend 

     ' Find the link to download file 
     Set oEleCol = .document.getElementsByTagName("A") 
     For Each oEle In oEleCol 
      If oEle.innerText = "Download file in csv format" Then 
       oEle.Click 
       Exit For 
      End If 
     Next 

     ' Wait for page to be ready 
     While .Busy 
      DoEvents 'wait until IE is done loading page. 
     Wend 

     ' Download file 
     DownloadFile .hwnd 

     ' Close IE 
     .Quit 

    End With 

End Sub 

注:
1.あなたは、この行をコメントアウトすることができますブラウザのウィンドウを最大化するために使用します:ShowWindow .hwnd, SW_SHOWMAXIMIZED
2. DownloadFileは関数呼び出しです。あなたはここで機能を見つけることができます。How to download a file from internet explorer using VBA
3.変更シート名を何でも自分のシートに
4.変更され、あなたの参照が

+0

どの行がエラーをスローしますか? – Zac

+0

私はそれがエラーを投げているIEオブジェクトだと思う。これはIEオブジェクトを作成していた場所でMicrosoft Internet Controlsを使用しているためです。上記のコントロールを参照するには、 'Tools'メニューから' References'をクリックしてください。これでウィンドウが開きます。 Microsoft Internet Controlsが見つかるまでスクロールして選択し、「OK」ボタンを押します。これで問題が解決するはずです – Zac

+0

私はコードを更新して、それらのエラーをもう取り除かないようにしました。私が提供したリンクから** DownloadFile **機能を取得することを忘れないでください。 – Zac

関連する問題