0

我一直在研究许多不同的论坛,YouTubing 就像疯了一样,并且发现了一些我怀疑很接近的东西,但我无法获得我想要的效果。我相当有信心知道执行特定流程所需的步骤,但我正在寻求任何愿意伸出援手的人的帮助。

意图(为什么这对您也有用):

我负责(为我的老板)安排对许多不同房地产的实地考察。每个属性都有一个不同的潜在客户联系人,该联系人会定期更改。我一直在努力创建一个电子表格:

  • 在任何给定时间,密切关注每个客户处于调度过程中的哪个步骤
  • 提供一个直观的平台,让每位客户在被要求安排约会时保持最新的联系信息、会议时间和杂项记录
  • 将前两个要点中的数据连接到地图上的属性并用颜色编码(通过 BatchGeo.com 在 Google 地图中)。

这将如何有用的案例示例 通过在地图上可视化这些数据并创建组(由不同颜色的谷歌地图图钉表示),人们可以直观地查看地图并为彼此靠近的站点安排连续约会“一举两得。”

如何手动完成此过程:

我想自动化导航到先前创建的 URL(编辑地图链接)的过程,将给定单元格范围内的所有单元格(即 A1:E10)复制并粘贴到具有该“编辑地图链接”的特定表单中,然后单击更新按钮。此外,所有导航都应在 Excel 中使用嵌入式 Web 浏览器完成(无需打开单独的浏览器)。

//批量地理“edt地图”链接

// http://batchgeo.com/map/edit/?map_id=2874687&d=0aa639559d0883376a15e66afdc042b0
//网站源代码printscreen http://printscreen.me/snaps/d906d04b89b98d54b4bfa6fd174e911cd08e8a1f

代码草案

Private Sub CommandButton1_Click()

    WebBrowser2.Navigate2 ActiveSheet.Range("C15").Value

    WebBrowser2.Document.getElementById("edit_form").Range.("B3:I7").Value

End Sub
4

1 回答 1

0

假设 IWebBrowser2 像 IE 一样工作,这应该可以解决问题。我已经使用 IE 对此进行了测试,因为我对此更熟悉,但我认为它应该是相同的。

注意: B3:I7 范围中的第一行需要包含标题(姓名、电话号码等),否则将提示您验证地址,只需确保您的工作表格式正确发送到表格。

Option Explicit
Sub LogMeIn()
'Requires reference to Microsoft HTML Object Library
Dim ie As InternetExplorer
Dim htmlDoc As HTMLDocument
Dim el As HTMLFormElement
Dim pasteValues As String
Dim vals As Range
Dim r As Long
Dim c As Long

'## Store the values in a delimited string
Set vals = Range("B3:I7")
For r = 1 To vals.Rows.Count
    For c = 1 To vals.Columns.Count
        If Not c = 1 Then
            pasteValues = pasteValues & vbTab & vals(r, c)
        Else:
            pasteValues = pasteValues & vbNewLine & vals(r, c)
        End If

    Next
Next

'## Create an instance of IE (alternatively you can probably use WebBrowser2)
Set ie = New InternetExplorer

'## So you can see what's happening/debug. delete the next line if you want.
ie.Visible = True

'## Navigate to the URL:
ie.Navigate "http://batchgeo.com/map/edit/?map_id=2874687&d=0aa639559d0883376a15e66afdc042b0"

'## Make sure the page has finished loading
Do Until ie.ReadyState = 4
    DoEvents
Loop

'## Set our Document variable
Set htmlDoc = ie.Document

'## Set the element variable
Set el = htmlDoc.getElementById("sourceData")

'## Send the values to the form
el.innerText = pasteValues
'## I use this to confirm I have grabbed the correct element, you can delete or comment it out.
MsgBox "The form now contains the following data, although it may not be visible:" & _
        vbNewLine & vbNewLine & _
        pasteValues

'## Update the map
htmlDoc.getElementById("mapnow_button").Click

'## Cleanup
Set ie = Nothing
End Sub
于 2013-06-19T14:23:07.473 回答