2017-04-05 42 views
1

我坚持以下任务:从Excel文件我发送数据(对于某一列到表单中我发送单元格值)到特定的IE对象预定义。发送输入(〜)密钥使用vba到外部IE对象

使用宏将数据发送到textarea字段中的网站(通过ID:id1在网站上标识)。对于添加到网站的textarea字段中的每个单元格值/数据,需要自动完成/附加Enter键/命令,因为这会生成一些空的输入字段,以便自动在网站上完成(代码如下:)

我用自动的方法挣扎发送ENTER键到网站变成textarea的数据插入

代码更新..

Sub adddata() 

    Dim objIE As Object 
    Dim objTR As Object 
    Dim i, j, counter As Integer 
    Dim lastRow As Long 
    counter = 1 

    Set objIE = GetIeByTitle("https://exampletest.com", True, True) 

    Dim lastRow2 As Integer 
    lastRow2 = Workbooks(path1).Worksheets("Test").Range("A" & Rows.Count).End(xlUp).Row 

    Workbooks(path1).Worksheets("Test").Activate 

    contor = 1 

    'First of all the unhidden files have to be take from the target excel file 
    'Selecting the unhidden lines from the excel file 
    For j = 1 To lastRow2 
     If Rows(j).EntireRow.Hidden = False Then 
      Workbooks(path1).Worksheets("Test").Range("A" & j & ":Z" & j).Select 
      Selection.Copy 
      ThisWorkbook.Worksheets("Test2").Range("A" & counter).PasteSpecial 
      counter = counter + 1 
     End If 
    Next j 

    'look into the new excel file containing just the unhidden lines 
    'Afterwards a look up through new excel file cells 
    For i = 2 To counter 
     objIE.document.getelementbyid("id1").Value = Worksheets("Test2").Range("C" & i).Value ' taking the value from the cell and adding it on the text area field 
     objIE.document.getelementbyid("id1").SetFocus 
     Application.SendKeys "~" ' sending the enter key 
     Application.Wait (7)  ' add the delay of 7 seconds 

     '2nd field 
     objIE.document.getelementbyid("id2").Value = Worksheets("Test2").Range("D" & i).Value 

     '3rd field 
     objIE.document.getelementbyid("id3").Value = Worksheets("Test2").Range("E" & i).Value 

    Next i 

End Sub 
+2

这是你的实际代码?它不会编译... –

回答

0

它看起来像您选择缺少一个右这里的支架:

Set objIE = GetIeByTitle("https://exampletest.com", True, True ***)*** 

尝试把牙套周围的波浪线:

Application.SendKeys "{~}" 

编辑:

听起来也许有与文本框的变化相关联的代码;或许尝试:

objIE.document.getelementbyid("id1").fireevent ("onchange") 
+0

@ georgian1990你是否收到错误信息?修复OP中的代码,使其包含可编译的[mcve],也可以帮助人们帮助你。 “不起作用”仅仅是一种建设性的评论。 –