导出日期字段和下拉到IE

时间:2015-04-28 07:08:02

标签: vba

我试图通过VBA将大约15个奇数字段填充到IE中并使用以下代码。虽然所有文本字段都是pouplated,但我无法填充日期字段和下拉字段。

Private Sub CommandButton4_Click()
    Dim IE As SHDocVw.InternetExplorer
    Dim URL As String

    URL = Sheet1.Range("A1").Value

    Set IE = GetIEWindow2
    If IE Is Nothing Then
        Set IE = New SHDocVw.InternetExplorer
    End If

    With IE
        .Visible = True


    IE.Document.all(Sheet1.Range("F6").Value).Value = Sheet1.Range("B10").Value
    IE.Document.all(Sheet1.Range("G6").Value).Value = Sheet1.Range("B11").Value
    IE.Document.all(Sheet1.Range("H6").Value).Checked = True 'Entered
    IE.Document.all(Sheet1.Range("I6").Value).Checked = True 'Entered
    IE.Document.all(Sheet1.Range("J6").Value).Value = Sheet1.Range("B14").Value
    IE.Document.all(Sheet1.Range("K6").Value).Value = Sheet1.Range("B15").Value
    IE.Document.all(Sheet1.Range("L6").Value).Value = Sheet1.Range("B16").Value
    IE.Document.all(Sheet1.Range("M6").Value).Value = Sheet1.Range("B17").Value
    IE.Document.all(Sheet1.Range("N6").Value).Value = Sheet1.Range("B18").Value 'for date in the format 28/04/2015 00:00:00
    IE.Document.all(Sheet1.Range("O6").Value).Value = Sheet1.Range("B19").Value
    IE.Document.all(Sheet1.Range("P6").Value).Value = Sheet1.Range("B20").Value
    IE.Document.all(Sheet1.Range("Q6").Value).Value = Sheet1.Range("B21").Value
    **IE.Document.all(Sheet1.Range("R6").Value).Value = Sheet1.Range("B22").Value** 'this is for drop down

    End With

End Sub


Private Function GetIEWindow2() As SHDocVw.InternetExplorer

    'Look for an IE browser window and, if found, return that browser as an InternetExplorer object.  Otherwise return Nothing

    Dim Shell As Object
    Dim IE As Object
    Dim i As Variant 'Must be a Variant to index Shell.Windows.Item() array

    Set Shell = CreateObject("Shell.Application")

    i = 0
    Set GetIEWindow2 = Nothing
    While i < Shell.Windows.Count And GetIEWindow2 Is Nothing
        Set IE = Shell.Windows.Item(i)
        If Not IE Is Nothing Then
            Debug.Print IE.LocationURL, IE.LocationName
            If TypeName(IE) = "IWebBrowser2" Then
                If TypeOf IE Is SHDocVw.InternetExplorer And IE.LocationURL <> "" And InStr(IE.LocationURL, "file://") <> 1 Then
                    Set GetIEWindow2 = IE
                End If
            End If
        End If
        i = i + 1
    Wend

End Function

0 个答案:

没有答案