Html 如何将数据从excel复制/粘贴到网页(VBA)?

Html 如何将数据从excel复制/粘贴到网页(VBA)?,html,excel,vba,Html,Excel,Vba,因此,我尝试使用VBA将数据从excel复制/粘贴到网页文本框中。但是,我的问题是,如果复制了3行或4行数据,当使用vba将值粘贴到网页中时,将只复制1行而不是所有行 这是我的密码: .Document.getElementsByTagName("textarea")(0).Value = ActiveCell.Value 有什么想法吗?如果我取出(0),我会得到一个错误: 对象不支持此属性或方法 这是我的一些代码: Sub FillOutInvoice(Account As Account)

因此,我尝试使用VBA将数据从excel复制/粘贴到网页文本框中。但是,我的问题是,如果复制了3行或4行数据,当使用vba将值粘贴到网页中时,将只复制1行而不是所有行

这是我的密码:

.Document.getElementsByTagName("textarea")(0).Value = ActiveCell.Value
有什么想法吗?如果我取出(0),我会得到一个错误:

对象不支持此属性或方法


这是我的一些代码:

Sub FillOutInvoice(Account As Account)

    Dim ie As InternetExplorer
    Dim elem As HTMLLinkElement

    Set ie = New InternetExplorer
    ie.Visible = True
    ie.navigate Settings.ErpAddress

    Do While ie.Busy Or ie.readyState <> 4
        DoEvents
    Loop

    With ie.document
        .getElementsByClassName(Settings.InputClass)(0).innerText = Account.InvoiceNumber
        .getElementsByClassName(Settings.InputClass)(1).innerText = Day(Account.InvoiceDate)
    End With

    Do While ie.Busy Or ie.readyState <> 4
        DoEvents
    Loop

    Application.Wait Now + #12:00:02 AM#
    ie.Quit

End Sub
Sub-filloutingvoice(帐户作为帐户)
Dim ie作为InternetExplorer
模糊元素作为HTMLINKELENT
Set ie=新的InternetExplorer
可见=真实
ie.navigate Settings.ErpAddress
在忙或准备状态4时执行
多芬特
环
用ie文件
.GetElementsByCassName(Settings.InputClass)(0).innerText=Account.InvoiceNumber
.getElementsByClassName(Settings.InputClass)(1).innerText=Day(Account.InvoiceDate)
以
在忙或准备状态4时执行
多芬特
环
申请。现在等待+#12:00:02 AM#
即退出
端接头

如您所见,所需的属性是
.InnerText
,而不是
.Value

。下面是使用剪贴板将一系列行文本发送到textarea元素的示例

Option Explicit
'VBE > Tools > References:
' Microsoft Internet Controls

Public Sub InsertData()
    Dim ie As New InternetExplorer
    With ie
        .Visible = True
        .Navigate2 "https://www.google.com/search?q=google+translate&rlz=1C1GCEB_enGB815GB815&oq=google+tran&aqs=chrome.0.0j69i57j0l4.2057j0j7&sourceid=chrome&ie=UTF-8"

        While .Busy Or .readyState < 4: DoEvents: Wend

        Dim clipboard As Object
        Set clipboard = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

        ActiveSheet.Range("A1:A3").Copy

        With clipboard
            .GetFromClipboard
            ie.document.getElementsByTagName("textarea")(1).innerText = .GetText
        End With
        Application.CutCopyMode = False
        Stop
        .Quit
    End With
End Sub
选项显式
'VBE>工具>参考:
“Microsoft Internet控件
公共子InsertData()
Dim ie成为新的InternetExplorer
与ie
.Visible=True
.导航2“https://www.google.com/search?q=google+translate&rlz=1C1GCEB_enGB815GB815&oq=google+tran&aqs=chrome.0.0j69i57j0l4.2057j0j7&sourceid=chrome&ie=UTF-8“
当.Busy或.readyState<4:DoEvents:Wend时
将剪贴板变暗为对象
设置剪贴板=CreateObject(“新建:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}”)
活动页。范围(“A1:A3”)。副本
带剪贴板
.GetFromClipboard
ie.document.getElementsByTagName(“textarea”)(1.innerText=.GetText
以
Application.CutCopyMode=False
停止
退出
以
端接头

范围的内容(“A1:A3”)


首先,第二,您是否打算使用
…Value=Selection.Value
?好的,谢谢!我已经尝试过selection.value,但是当您尝试调试某些东西时,会出现“自动化错误”,使用硬编码值不是一个坏主意。例如,
.Value=“Some test”
以查看问题所在并消除可能的原因。您的错误是因为。Value不是元素集合的属性,如果删除索引(例如0),元素集合就是元素集合的属性。是否尝试将数据从一个范围(行数)粘贴到单个元素中?或者,您需要在行上循环以分配给不同的元素吗?@QHarr,我在excel中设置了一个数据集,并设置了一个过滤器,第一列的所有行都会自动复制。这是我想粘贴到网页文本框中的数据。