2017-01-12 14 views
0

私はVBAを使用して、レポートサーバーに日付固有のレポートを作成しています。日付パラメータをURLに入力することで、日付ピッカーをバイパスすることができました。次のステップは、レポートをExcelにエクスポートすることです。ファイルタイプを選択するためのドロップダウンがあります。ドロップダウンからコードを選択するコードを取得するにはどうすればよいですか?私は以下のコードの多くのバリエーションを試しました。エクスポートエクスポートドロップダウンメニューがあるVBAを使用してIEレポートをエクスポートしてください

Sub Report() 
    Dim ie As Object 
    Application.ScreenUpdating = False 
    Set ie = CreateObject("Internetexplorer.Application") 
    ie.Visible = True 
    ie.navigate "http://reportserver.comp.local/ReportServer/Pages/ReportViewer.aspx?%2fOperations%2fAR%2fCash+Receipts&StartDate=2017-01-07&EndDate=2017-01-13" 
    ie.document.getelementbyid("ReportViewerControl_ctl05_ctl04_ctl00_ButtonImgDown").Click 
    ie.document.getelementbyid("ReportViewerControl_ctl05_ctl04_ctl00_Menu").Click 
    ie.document.getelementbyid("ReportViewerControl_ctl05_ctl04_ctl00_Button").Value = "Excel" 

答えて

0

ドロップダウンオプションを通過し、あなたが後にある選択し、その特定selectedIndexを変更する必要があります。以下を試してください:

Option Explicit 

Sub Report() 
    Dim ie As Object, oSelection As Object, i As Long 
    Application.ScreenUpdating = False 
    Set ie = CreateObject("Internetexplorer.Application") 
    If ie Is Nothing Then Exit Sub 
    With ie 
     .Visible = True 
     .navigate "http://reportserver.comp.local/ReportServer/Pages/ReportViewer.aspx?%2fOperations%2fAR%2fCash+Receipts&StartDate=2017-01-07&EndDate=2017-01-13" 

     ' I am guessing this is the right id check page source code "<select id='...'" 
     Set oSelection = .document.getelementbyid("ReportViewerControl_ctl05_ctl04_ctl00_Menu") 

     If Not oSelection Is Nothing Then 
      For i = 0 To oSelection.all.Length - 1 
       If InStr(1, oSelection.all(i), "Excel", vbTextCompare) > 0 Then 
        oSelection.selectedIndex = i 
        Exit For 
       End If 
      Next 
      Set oSelection = Nothing 
     End If 
     .Quit 
    End With 
    Set ie = Nothing 
    Application.ScreenUpdating = True 
End Sub 
+0

Excelオプションが最初のオプションです。私は、テーブル用のもの、ボタン用のもの、ボタンイメージ用のもの、ドロップダウンメニュー用のものがあるので、私が正しいIDを使用しているかどうか、少し混乱しています...私はすべてを試しましたそれらのうち何も動作していません。私は、Format = EXCELOPENXMLのようなものを書くことができるかどうかを調べようとしていましたが、そう簡単ではないと思います。 – chef

+0

FireFoxをお持ちの場合は、領域または選択ドロップダウンボックスを選択し、ソースコードを表示すると、それを見つけることができるはずです。 IEを使用する場合、BreakPointを '.Quit'に置き、コードを実行し、希望のオプションに変更しない場合は、黄色の矢印を' If Not oSelection ... 'に移動し、IDを即時ウィンドウ 'Set oSelection = .document.getelementbyid("次のテストID ")'を選択し、必要なものが変更された場合は、必要なものを選択します。 – PatricK

関連する問題