Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA Run Time Error '424' object required

Tags:

I am totally new in VBA and coding in general, am trying to get data from cells from the same workbook (get framework path ...) and then to start application (QTP) and run tests.

I am getting this error when trying to get values entered in excel cells:

Run Time Error '424' object required

I believe I am missing some basic rules but I appreciate your help. Please see below the part of code in question:

Option Explicit

Private Sub RunTest_Click()

    Dim envFrmwrkPath As Range
    Dim ApplicationName As Range
    Dim TestIterationName As Range
    'Dim wb As Workbook
    'Dim Batch1 As Worksheets
    Dim objEnvVarXML, objfso, app As Object
    Dim i, Msgarea

    Set envFrmwrkPath = ActiveSheet.Range("D6").Value ' error displayed here
    Set ApplicationName = ActiveSheet.Range("D4").Value
    Set TestIterationName = ActiveSheet.Range("D8").Value
like image 230
user3232996 Avatar asked Jan 26 '14 01:01

user3232996


People also ask

How do you fix run time error 424?

Object name used in script does not match the object name on the picture. Rename the object on the picture to match the name of the object in the VBA script.

What is object required in VBA?

The “Object required” means object data type reference needs to be accurate. When the Option Explicit word is unenabled in the coding, we will get an “Object Required” error for misspelled variable words. If Option Explicit is enabled, we will get the variable not defined error for misspelled variable words.


1 Answers

The first code line, Option Explicit means (in simple terms) that all of your variables have to be explicitly declared by Dim statements. They can be any type, including object, integer, string, or even a variant.

This line: Dim envFrmwrkPath As Range is declaring the variable envFrmwrkPath of type Range. This means that you can only set it to a range.

This line: Set envFrmwrkPath = ActiveSheet.Range("D6").Value is attempting to set the Range type variable to a specific Value that is in cell D6. This could be a integer or a string for example (depends on what you have in that cell) but it's not a range.

I'm assuming you want the value stored in a variable. Try something like this:

Dim MyVariableName As Integer
MyVariableName = ActiveSheet.Range("D6").Value

This assumes you have a number (like 5) in cell D6. Now your variable will have the value.

For simplicity sake of learning, you can remove or comment out the Option Explicit line and VBA will try to determine the type of variables at run time.


Try this to get through this part of your code

Dim envFrmwrkPath As String
Dim ApplicationName As String
Dim TestIterationName As String
like image 137
Automate This Avatar answered Sep 19 '22 19:09

Automate This