paddykool
asked on
VB CallByName - Error message:Object required
Hi All,
I'm working on a little routine that will use the CallbyName function to call a function on a class that I wrote. This is all in Excel VBA. Now, I get an error on the line
" CallByName TextBoxObject, "SetTextBox", CallType.VbSet, Arguments()"
Error : Object required.
I'm doing something wrong (obviously!!) but I still don't think i've fully got my head around "CallByName"
What i'm essentially trying to achieve is to replace the line:
TextBox.SetTextBox "textboxa", "Hello A" by calling the CallByName function
Can anyone give some guidence - please!!!
I'm working on a little routine that will use the CallbyName function to call a function on a class that I wrote. This is all in Excel VBA. Now, I get an error on the line
" CallByName TextBoxObject, "SetTextBox", CallType.VbSet, Arguments()"
Error : Object required.
I'm doing something wrong (obviously!!) but I still don't think i've fully got my head around "CallByName"
What i'm essentially trying to achieve is to replace the line:
TextBox.SetTextBox "textboxa", "Hello A" by calling the CallByName function
Can anyone give some guidence - please!!!
Sub Test2()
Dim TextBox As ClassTextBox
Dim Arguments(1) As String
Dim TextBoxCollection As Object
Dim TextBoxObject As Object
Set mIE = New SHDocVw.InternetExplorer
mIE.Visible = True
' Set the URL
mIE.Navigate "C:\IE Automation Test Page.html"
' TextBox.SetTextBox "textboxa", "Hello A"
Arguments(0) = "textboxa"
Arguments(1) = "HELLO A"
Set TextBoxCollection = mIE.Document.getElementsByName("textboxa")
Set TextBoxObject = TextBoxCollection(0)
CallByName TextBoxObject, "SetTextBox", CallType.VbSet, Arguments()
End Sub
ClassTextBox: . . .
Option Explicit
Public Function SetTextBox(TextBoxName As String, TextBoxValue As String)
Dim TextBox As Object
Set TextBox = mIE.Document.getElementsByName(TextBoxName)
TextBox(0).Value = TextBoxValue
End Function
ASKER
Hi,
Thanks for the reply. I'm still getting the error "Object Required".
I think its something to do with the way my method is made in my ClassTextBox.
If you look at my SetTextBox method (which yes, sets text inside a text box), it take two arguments, the name attribute of the textbox and the value to set inside it. This is why I was putting both of these arguments into the arguments() array.
I done a watch on my TextBoxObject and it fine. Thought it to be a buit dogey as getElementsByName returns a collection.
So . . . where am I going wrong?!?
Also, can you explain the useCallType?!? aside, would it be possible to use CallType.Method as setTextBox is a method?!?
All help greatly appreciated
Thanks for the reply. I'm still getting the error "Object Required".
I think its something to do with the way my method is made in my ClassTextBox.
If you look at my SetTextBox method (which yes, sets text inside a text box), it take two arguments, the name attribute of the textbox and the value to set inside it. This is why I was putting both of these arguments into the arguments() array.
I done a watch on my TextBoxObject and it fine. Thought it to be a buit dogey as getElementsByName returns a collection.
So . . . where am I going wrong?!?
Also, can you explain the useCallType?!? aside, would it be possible to use CallType.Method as setTextBox is a method?!?
All help greatly appreciated
ASKER
Also, perhaps its something to do with the fact that its a DOM object?!?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks but unfortunately
" CallByName TextBoxObject, "SetTextBox", VbMethod, "textboxa", "HELLO A" did not work
However, it did produce an error message "Object does not support this property or method...hmmm
This is coming from using "VbMethod" rather than "CallType.VbSet" (or CallType.vbMethod)
Anywho, there is something unorganised about the way i'm doing this.
Whats the deal with using "SetText" insterad of "SetTextBox"?!? I have to use my method "SetTextBox" as i want to use lots of other functions in ClassTextBox by this way.
To give a breif outline of what i'm up to (stop reading from here as this may bore...!!!)
I have a spread sheet with 3 columns
Control, Method, Data
All the columns contain key word that will drive the script
Control contains the class (ClassTextBox), and the HTML name of the textbox (textboxa)
Method contains the method in my ClassTextBox (SetTextBox)
Data contain the data to use with the methed call (HELLO A)
What I'm trying to do here is create a driver script that will read of this sheet, do a spot of parsing and pass the nessary arguments to the function CallByName to perform the task on web page...
Now, I'm going to stick with the above for now but aside, anyone got a better suggestion for what I'm try to?!? I'll open a different tread perhaps but sure we'll stick with the issue at hand for now.
Thanks people!!!
" CallByName TextBoxObject, "SetTextBox", VbMethod, "textboxa", "HELLO A" did not work
However, it did produce an error message "Object does not support this property or method...hmmm
This is coming from using "VbMethod" rather than "CallType.VbSet" (or CallType.vbMethod)
Anywho, there is something unorganised about the way i'm doing this.
Whats the deal with using "SetText" insterad of "SetTextBox"?!? I have to use my method "SetTextBox" as i want to use lots of other functions in ClassTextBox by this way.
To give a breif outline of what i'm up to (stop reading from here as this may bore...!!!)
I have a spread sheet with 3 columns
Control, Method, Data
All the columns contain key word that will drive the script
Control contains the class (ClassTextBox), and the HTML name of the textbox (textboxa)
Method contains the method in my ClassTextBox (SetTextBox)
Data contain the data to use with the methed call (HELLO A)
What I'm trying to do here is create a driver script that will read of this sheet, do a spot of parsing and pass the nessary arguments to the function CallByName to perform the task on web page...
Now, I'm going to stick with the above for now but aside, anyone got a better suggestion for what I'm try to?!? I'll open a different tread perhaps but sure we'll stick with the issue at hand for now.
Thanks people!!!
ASKER
Oh, SRigney: yes, Set TextBoxCollection = mIE.Document.getElementsBy Name("text boxa") is returning a collect but I'm working with a HTML page that i made and it has only one textbox named textboxa in it.
Also, the following line Set TextBoxObject = TextBoxCollection(0) creates a reference to that specific object.
Thanks :)
Also, the following line Set TextBoxObject = TextBoxCollection(0) creates a reference to that specific object.
Thanks :)
ASKER
Hi All,
I found the solution!!!
By adding the lines:
Dim c As ClassTextBox
Set c = New ClassTextBox
and then calling the function using
CallByName c, "SetTextBox", VbMethod, "textboxa", "HELLO A"
The correct action was performed. I got confused as I was passing in the actual object instead of and instance of my class
I found the solution!!!
By adding the lines:
Dim c As ClassTextBox
Set c = New ClassTextBox
and then calling the function using
CallByName c, "SetTextBox", VbMethod, "textboxa", "HELLO A"
The correct action was performed. I got confused as I was passing in the actual object instead of and instance of my class
I'm guessing that you are setting the text not the textbox. And the value you want to pass is the text for it.
for that you should need
CallByName TextBoxObject, "SetText", CallType.VbSet, "HELLO A"