spaceranger
New Member
- Joined
- Oct 8, 2013
- Messages
- 6
Hi guys
Long time lurker, fist time poster. I'm in need of help to make VBA select and paste a selection from a worksheet in the main field on Create a map | BatchGeo.. . The code is put together from two other codes and my own parts. All the commented lines are things that I've tried and later deactivated.
IT GOES WRONG right around the bold text - I fail to select the field which is needed in order to access it and later paste text in it. I think the name of the field is sourceData (from looking at source code via my browser).
The code IS able to press the button to execute the procedure - but this is done after the text is supposed to be pasted.
Do you know the command to cure my problems?
Thanks!:
Long time lurker, fist time poster. I'm in need of help to make VBA select and paste a selection from a worksheet in the main field on Create a map | BatchGeo.. . The code is put together from two other codes and my own parts. All the commented lines are things that I've tried and later deactivated.
IT GOES WRONG right around the bold text - I fail to select the field which is needed in order to access it and later paste text in it. I think the name of the field is sourceData (from looking at source code via my browser).
The code IS able to press the button to execute the procedure - but this is done after the text is supposed to be pasted.
Do you know the command to cure my problems?
Thanks!:
Code:
Option Explicit
Sub GeoBatchSelection()
'Requires reference to Microsoft HTML Object Library
Dim ie As Object '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 = Selection '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
Set ie = CreateObject("internetexplorer.application")
'## 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
'While ie.busy
' DoEvents
'Wend
'## Set our Document variable
'Set htmlDoc = ie.Document
'## Set the element variable
'Set el = htmlDoc.getElementById("sourceData")
'## click in sourceData to make paste possible
'ie.document.getelementbystyle("display: none;").Focus
'ie.document.getelementbyclass("tableize").Click
[U][I][B]ie.document.getelementbyid("sourceData").Focus
ie.document.getelementbyid("sourceData").Click
[/B][/I][/U]
'## Send the values to the form
'el.innerText = pasteValues
[I][U][B] ie.document.getelementbyid("sourceData").Value = pasteValues[/B][/U][/I]
'## 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
ie.document.getelementbyid("mapnow_button").Click
'## Cleanup
Set ie = Nothing
End Sub