vba 复制单元格并粘贴到网络表单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18776125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 23:18:20  来源:igfitidea点击:

Copy cell and paste to web form

excelexcel-vbavba

提问by user2774606

I'm trying to create an order-tracking macro that does the following after I have selected a specific cell:

我正在尝试创建一个订单跟踪宏,在选择特定单元格后执行以下操作:

  1. Opens the order tracking webpage, e.g. FedEx shipment tracking
  2. Enters the value of a selected cell in my Excel spreadsheet into the appropriate search box on the webpage
  3. Clicks submit
  1. 打开订单追踪网页,例如 FedEx 货件追踪
  2. 将 Excel 电子表格中选定单元格的值输入到网页上的相应搜索框中
  3. 点击提交

I'm working in Excel 2010 off of a sample code I found on another forum. The code accomplishes everything EXCEPT pasting the value of a GIVEN cell. I can assign a numerical value or specific cell value to be entered, but I need a universal macro that I can use for any given cell.

我正在 Excel 2010 中使用我在另一个论坛上找到的示例代码。除了粘贴 GIVEN 单元格的值之外,该代码完成了所有操作。我可以指定要输入的数值或特定单元格值,但我需要一个通用宏,可以用于任何给定单元格。

I tried using some basic copy paste functions with the active cell. I managed to select and copy the active cell, but not to paste it into the search box.

我尝试在活动单元格中使用一些基本的复制粘贴功能。我设法选择并复制活动单元格,但没有将其粘贴到搜索框中。

Here is the code with problem sections identified.

这是识别出问题部分的代码。

Dim IE As Object

Sub submitFeedback3()

    Application.ScreenUpdating = False

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate "TrackingWebsite"

    Application.StatusBar = "Submitting"
    ' Wait while IE loading...
    While IE.Busy
        DoEvents
        ActiveCell.Select
        Selection.Copy
    Wend
    ' **********************************************************************
    delay 1
        IE.Document.getElementById("receipt").Click
    delay 1
        IE.Document.getElementById("receipt").Paste
    delay 2
        IE.Document.getElementById("submit").Click
    '**********************************************************************

End Sub

Private Sub delay(seconds As Long)
    Dim endTime As Date
    endTime = DateAdd("s", seconds, Now())
    Do While Now() < endTime
        DoEvents
    Loop
End Sub

When I tried copy/paste code, I used the following underneath DoEvents:

当我尝试复制/粘贴代码时,我在 DoEvents 下使用了以下内容:

ActiveCell.Select
Selection.Copy

回答by JaneGoodall

IE.Document.getElementById("appReceiptNum").Click 
delay 1
IE.Document.getElementById("appReceiptNum").Paste

works for me, on a different site of course.

对我有用,当然是在不同的网站上。

If it works for you too, make sure to upvote and click the check mark next to this answer!

如果它也适用于您,请确保投票并单击此答案旁边的复选标记!