PDA

View Full Version : Filling out an online form



Mango Eldar
03-12-2012, 03:10 AM
Hello everyone, first post, exciting!

I am trying to write a macro which fills out an online form using information from a word doc. I know next to nothing about VBA but with the help of forums I have been able to make a lot of progress. I have been able to fill out most components of this form but now I have run into an issue which no one has been able to help me with, I was hoping someone here would be able to crack this problem.

I am having trouble filling out one of the input-boxes on the form.

I have to preface everything by saying that my understanding of HTML and VBA are very limited so I encourage everyone to take my assumptions with a pinch of salt.

Attached is a picture of the form with my trouble input boxes labelled:

Input box 2 in particular has given me a lot of strife.

When one clicks on this input box, the text “click here to add content” disappears and a blinking cursor appears in the box indicating it can be edited.

I have found a name/id for the input-box which lets me select it (i.e puts a cursor in the box) but I cant seem to use the same name/id to insert a value into that input box.

This page was designed to be accessed by internet explorer so it behaves quite differently if accessed in chrome. When I click on the box in chrome, the text “click here to add content” does not disappears and a blinking cursor does not appears in the box, instead, an editable version of the box pops up in a new window with a different URL to the original page. A friend of mine suggested that relevant source code for this box cannot be found on the original page, instead that I should be looking for it in the source code of the popup box.

Attached (in next post) is the source for both the original page containing box #2 and the source for the page that pops up when the box is clicked on (both retrieved from Chrome).

Below is the code I have for my macro so far.


' sets first paragraph as document
myvar = ThisDocument.Paragraphs(1)
' sets variable for paragraph 2 till the end of the document
Set r = ThisDocument.Range ' set whole document to range objectr.
Start = ThisDocument.Paragraphs(2).Range.Start ' move start to paragraph 2
mytxt = r.Text 'assign text value of range to string variable
Set wb = CreateObject("internetexplorer.application")
wb.navigate2 "intranet homepage"
wb.Visible = True
'optional
Do Until wb.readystate = 4
DoEvents
Loop
wb.Document.all("ctl00$PlaceHolderMain$pageTitleSection$ctl00$titleTextBox").Value = myvar
mychars = "!" 'add more to suit
For i = 1 To Len(mychars)
myvar = Replace(myvar, Mid(mychars, i, 1), "")
Next
myvar = Replace(myvar, " ", "-")
wb.Document.all("ctl00$PlaceHolderMain$pageTitleSection$ctl02$urlNameTextBox").Value = myvar
wb.Document.getElementById("ctl00$PlaceHolderMain$ctl00$RptControls$buttonCreatePage").Click
On Error Resume Next ' start inline error handling
Do
Err.Clear
DoEvents
wb.Document.getElementById("ctl00_PlaceHolderMain_content_ctl00_RichHtmlField____AddContentPromptLink").Click
Loop Until Err.Number = 0
On Error GoTo 0 ' turn off inline error handling
'clicks on text editor
wb.Document.getElementById("ctl00_PlaceHolderMain_content_ctl00_RichHtmlField____AddContentPromptLink").Click




Most of this code fills out other parts of the form, the last line selects intput-box 2, any code to paste a value into the intput-box would be added to the end.



Temporary sendkeys solution:

My macro is very close to being usable, I really only need to solve a handful of problems, but these last handful have taken longer than writing everything else. It would be really great if someone could help me write a temporary ‘idiot solution’ to this problem using sendkeys. Since I can already select the input-box, perhaps there is a way to write “wherever the cursor is now, paste variable X”, can someone help me do this? This would let me start using my macro while I figure out a smarter way of doing the same thing.

Thank so much in advance.

Mango Eldar
03-12-2012, 03:11 AM
Source.