使用VBA

时间:2018-02-22 16:28:52

标签: vba excel-vba excel

我正在尝试将文件上传到网页中。我按照以下步骤操作: 1.打开网页 2.寻找"输入"标签名称 3.找到标记名后,打开浏览器 4.在文件位置中输入文件路径名。 5.退出循环。

问题: 1.在步骤3中,一旦打开文件浏览器,预期循环将从浏览器返回。

打开浏览器后我尝试使用WScript,但没有运气。

如果有人有解决方案,请建议。

Sub File_Test()

Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLButtons As MSHTML.IHTMLElementCollection
Dim HTMLButton As MSHTML.IHTMLElement
Dim btnInput As MSHTML.IHTMLInputElement
Dim ie As Object
Dim pointer As Integer

Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
ie.navigate "http://www.htmlquick.com/reference/tags/input-file.html"

Do While ie.readyState <> READYSTATE_COMPLETE
Loop

Set HTMLDoc = ie.document
Set HTMLButtons = HTMLDoc.getElementsByTagName("input")

For Each HTMLButton In HTMLButtons
    For Each btnInput In HTMLButtons
        If btnInput.Type = "file" Then
            HTMLButton.Click
            btnInput.Value = "C:\temp\test.txt"
            pointer = 1
            Exit For
        End If
    Next btnInput

    If pointer = 1 Then Exit For

Next

End Sub

1 个答案:

答案 0 :(得分:-1)

你走了:

签出: Excel将文件上传到FTP站点

http://sam308.com/excel-upload-file-ftp-site