0

If you check out my history you will see that I have been calling Worksheets references through method calls. A working example of one such method:

'In module GlobalRefs

Function W_ExampleWS() As Worksheet
    Set W_ExampleWS = ActiveWorkbook.Worksheets("ExampleWS")
End Function

So when I do normal worksheet related calls, they work:

...
GlobalRefs.W_ExamplesWS.Range("A1").Value = 42 'works
...

However, the worksheet ExampleWS has a subroutine called "DesignGraph". I want to be able to call that subroutine through a method call like so.

'In module AnotherRandomModule

...
GlobalRefs.W_ExampleWS.DesignGraph arg1 arg2
...

I keep receiving errors like the method is undefined even though the VBA Editor's intellisense acknowledges the the existence of the subroutine as it corrects the capitalization of DesignGraph if spelt mis-cased. I am giving it the correct arguments.

Why is this happening?

3
  • is there or you missed comma between arg1 and arg2? Commented Jun 3, 2013 at 21:09
  • 1
    @JosieP has the answer (and a suggestion). A different approach might be to "wrap" the worksheet object in a custom class which exposes DesignGraph (and any other routines) as a method. This is a good approach if you want to model a specific worksheet "type", of which there could be many instances: it also avoids duplicating code in each instance of that type. Commented Jun 3, 2013 at 22:18
  • @KazJaw Sorry, that was a typo in the question. :s Commented Jun 4, 2013 at 13:45

1 Answer 1

1

the Worksheet class does not have a DesignGraph method - only your specific sheet does. Assuming DesignGraph is a public sub, if you change the function to return an Object instead you should not have an issue.

Sign up to request clarification or add additional context in comments.

1 Comment

I decided to go a different direction but your tid bit of knowledge helped me understand the issue I was facing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.