MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Excel macros

Posted by George on January 28, 2002 9:54 PM


when I run my macro for excel in Visual basic I find this error:

Runtime error 1004

Method 'Range' of object' - Global' failed

I think the error is in this statement:

y = funct("abc", Range("abc"), 1)

The function has been defined as follows:

Declare Function funct Lib "hello.XLL" (ByVal sheetName As Variant, ByVal Range As Variant, ByVal lockFlag As Variant) As Long

I tried y = funct("abc", "Range(abc)", 1)
but then the program is working and result is wrong.
Could you help me fix this problem.

Posted by Damon Ostrander on January 30, 2002 10:26 PM

Hi George,

It is impossible to be sure what is causing the error without knowing what the code is inside of the funct function in the hello XLL library. Nevertheless, I suspect strongly that the problem is the "Range(abc)" argument, because it does not make much sense to pass this string that looks sort of like a range as a string rather than a range object. I recommend you try passing it as Range("abc") instead (without the outer quotes), as this is a valid range object.

Good luck.


Posted by george on January 31, 2002 2:41 AM

I had tried Range("abc") alreadybut it does not work and returns the same error.

Posted by Damon Ostrander on February 05, 2002 10:24 AM

Hi again George,

1. Do you have a range named "abc" on the worksheet named "abc"? (You must if SheetName is actually a worksheet and Range is truly a Range object).

2. Is worksheet abc active when you call the function? (since you didn't qualify the Range object it must be on the active worksheet)

3. Did you create funct in hello.XLL yourself? If so, how about posting its code?