• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1227
  • Last Modified:

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!!!



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

Open in new window

0
paddykool
Asked:
paddykool
  • 5
  • 2
2 Solutions
 
SRigneyCommented:
I believe to replace the line TextBox.SetTextBox "textboxa", "Hello A"

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"

0
 
paddykoolAuthor Commented:
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
0
 
paddykoolAuthor Commented:
Also, perhaps its something to do with the fact that its a DOM object?!?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try this way:

    CallByName TextBoxObject, "SetTextBox", VbMethod, "textboxa", "HELLO A"
0
 
SRigneyCommented:
I think that Set TextBoxCollection = mIE.Document.getElementsByName("textboxa") is returning a standard web text box.  It may not know about your specific obects.

At that point you have a reference to the one object that you want to set the text into anyways.   You should be able to just setText.

using method instead of set is probably correct if you do not have both a set and get implemented with that name.   They are probably interpreted differently somehow.
0
 
paddykoolAuthor Commented:
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!!!
0
 
paddykoolAuthor Commented:
Oh, SRigney: yes, Set TextBoxCollection = mIE.Document.getElementsByName("textboxa") 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 :)
0
 
paddykoolAuthor Commented:
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now