Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Code From Excel To Internet Exporer and Fill Out 2 Fields

Status
Not open for further replies.

NewYorkFashionToGo

Programmer
Oct 20, 2006
44
US
I am about 90% done with what I want to do with this application and I dont know how to complete it so it completely works. The code below is from Excel and into my account to a new window where I then need to fill in My email address and then the second fill in box is to browse my hard drive to submit a file for upload. And then click submit. I could use some assistance. I am just learning how to interact applications with one another. This completely works up until where I need to fill it in.

Thanks in Advance

Chris

Sub LoginMe()

Dim appIE As Object

Set appIE = CreateObject("InternetExplorer.Application")
appIE.Visible = True

While appIE.busy
DoEvents
Wend

appIE.navigate "
While appIE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend

SendKeys "YOURUSERNAME", True
SendKeys "{TAB}", True
SendKeys "YOURPASSWORD", True
SendKeys "{TAB}", True
SendKeys "{ENTER}", True

End Sub
 
NewYorkFashionToGo,
If you are going to try the [tt]SendKeys[/tt] route I think you need to activate the IE window before you send the keys.

A better way would be to send your information to the IE form fields using the IE object ([tt]appIE[/tt]). Did you try the [tt]GetFields[/tt]/[tt]SetFields[/tt] routines in FAQ707-6399 How to automate web forms from VBA using Internet Explorer?

They will help you identify the fields on the IE form and provides a sample of how to send information back to the form.

Hope this helps,
CMP
 
That is pretty neat, I was able to do the Get Fields, But having trouble with the set fields, It is debugging on me.


Specifically in 3 places:

#1 Set objInputElement = objParent.Tags("INPUT").Item(ActiveSheet.Cells(lngRow,

cElement_Name).Text)

#2
objParent.Item(ActiveSheet.Cells(lngRow, cElement_Name).Text).Value = CStr(ActiveSheet.Cells(lngRow,

cElement_SetValue))
#3
ActiveSheet.Cells(lngRow, cElement_SetValue)

The whole code is below:

Im still relatively new to VBA and especially getting the programs to interact with one another. I do okay with keeping and working with the data in the same application.. This is like learning a new language, That is not in my dictionary just yet.

The Get fields worked great. Am I supposed to put the text that I want to upload on column IV in Excel in the appropriate row that the get field application supplied.
Just a little confused what to do.

Above the code in that thread you gave me it says this:
"2 SetFields(): Takes the above listing and pushes data back to the web page
using the last column in the worksheet."

Thanks for posting this, I appreciate it.







Sub SetFields()
On Error Resume Next
Dim objIE As Object
Dim objParent As Object
Dim objInputElement As Object
Dim lngRow As Long

Set objIE = GetIEApp
'Make sure an IE object was hooked
If TypeName(objIE) = "Nothing" Then
MsgBox "Could not hook Internet Explorer object", vbCritical, "GetFields() Error"
GoTo Clean_Up
End If

For lngRow = 2 To ActiveSheet.UsedRange.Rows.Count
If ActiveSheet.Cells(lngRow, cElement_SetValue) <> "" Then
'If we have a parent name/ID drill to that element, otherwise point to whole document
If ActiveSheet.Cells(lngRow, cForm_name).Text <> "" Then
Set objParent = objIE.Document.Forms(ActiveSheet.Cells(lngRow, cForm_name).Text)
ElseIf ActiveSheet.Cells(lngRow, cForm_Id).Text <> "" Then
Set objParent = objIE.Document.Forms(ActiveSheet.Cells(lngRow, cForm_Id).Text)
Else
Set objParent = objIE.Document.All
End If
With objParent
If ActiveSheet.Cells(lngRow, cElement_Type) = "radio" Then
Set objInputElement = objParent.Tags("INPUT").Item(ActiveSheet.Cells(lngRow,

cElement_Name).Text)
objInputElement.Item(ActiveSheet.Cells(lngRow, cElement_ID).Text).Checked = True
Set objInputElement = Nothing
ElseIf ActiveSheet.Cells(lngRow, cElement_Type) = "checkbox" Then
objParent.Item(ActiveSheet.Cells(lngRow, cElement_ID).Text).Checked = True
Else
objParent.Item(ActiveSheet.Cells(lngRow, cElement_Name).Text).Value = CStr(ActiveSheet.Cells(lngRow,

cElement_SetValue))
End If
End With
If Err.Number <> 0 Then
Debug.Print "Error Writting: Row " & lngRow, ActiveSheet.Cells(lngRow, cElement_Name),

ActiveSheet.Cells(lngRow, cElement_SetValue)
Err.Clear
End If
End If
Next lngRow
Clean_Up:
Set objParent = Nothing
Set objIE = Nothing
End Sub
 
Look into the "Microsoft Web Browser" control. It is used by placing it on a UserForm. To 'submit' data to a web page you have to use the "Post" method.
 
NewYorkFashionToGo,
My first guess is that the word-wrap needs to be fixed?
[tt]Set objInputElement = objParent.Tags("INPUT").Item(ActiveSheet.Cells(lngRow, cElement_Name).Text)[/tt]

CBasicAsslember,
IMHO the WebBrowser control is overrated and a pain to work with (at least in Access). It makes controlling the browser a little easier but as far as interacting with the web page the methods are the same as going to an external browser, so why not go straight to the source?

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Yes I got it working, You were right it had to do with the word wrap. I assume thier was carrage returns in the code. I do have another issue currently with this. Which I havent resolved yet.

I have been successful with filling out the form. That is not the problem, I see and understand how that works. What i cant seem to do is apply that same tecqunique for a find file dialog box. Browse my hard drive and submit file on the form. It works perfectly if it is just a text box on the page. Any Idea? I been browsing the board trying to find a solution with no luck yet.
 
NewYorkFashionToGo,
If you know the file path/name that you need to upload you can probably avoid the Find File dialog all together. Most sites I have seen return the path/name to a textbox (visible or hidden) on the webpage. You should be able to just set that value using the appropriate code.

Hope this helps,
CMP
 
Thanks Cautioun, I appreciate your help, I am little short on lingo still, I have tried many many searches on here an google to resolve that. Perhaps someone can recommend a book. The book is How to Interact with other office applications. I have 5 of them here. 2 with excel 2 with access and 1 with outlook, and I cant figure out what it is I need to look for. I have everything you helped me with and it was a hugh help and it works like a charm. I still cant get the text to appear in that upload box. I am definetly missing something, I think its the experience, the terms and the education. I am determined though, I will eventually nail it. I know that. LLittle frustrating when your looking for something and you dont know what your supposed to be looking for. LOL.... Ill get it....
 
NewYorkFashionToGo,
Sorry, I have no recommendations for a good book, especially when your dealing with automating Internet Explorer. My knowledge comes from forums, MSDN, and trial & error programming.

If your having problems getting the fields to show up using the Excel routine in the FAQ here a couple of things that routine won't look for.[ul]
[li]Are your fields in a Frame (HTML [tt]Frame[/tt]/[tt]Frameset[/tt] tags)?[/li]
[li]Are they in a floating frame (HTML [tt]IFrame[/tt] tags)?[/li]
[li]Is the filename held in a variable (some type of VB/J script)?[/li][/ul]

Hope this helps,
CMP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top