因此,我试图使用VBA将数据从excel复制/粘贴到网页文本框中。但是,我的问题是,例如,如果我复制了3或4行数据,那么在使用vba将值粘贴到网页中时,将仅复制1行,而不是所有行。
这是我的代码:
.Document.getElementsByTagName("textarea")(0).Value = ActiveCell.Value
有什么想法吗?如果我取出(0),则会收到错误消息:
对象不支持此属性或方法。
答案 0 :(得分:1)
这是我的一些有效代码:
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
如您所见,所需的属性是.InnerText
而不是.Value
。
答案 1 :(得分:0)
这里是使用剪贴板将一定范围的行文本发送到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
范围的内容(“ A1:A3”)