Solved

Cannot call subs in different sheets

Posted on 2014-01-06
3
242 Views
Last Modified: 2014-01-10
Hi All,

I am "self voting" this my most provincial question to date but I can't figure it out.  I have tried youtube and the usual places to get this kind of question asked.

I have a huge spreadsheet filled with VBA code from one end to the other.

In sheet19 I am trying to call a sub (not private) that is in sheet2.

My code goes something like this:

my sub()

'code here
'code here
'code here

call SubS2        'Sub from Sheet2 and it is not private so it should work

End Sub


So I know that I am doing something so silly that it hurts.

I have tried call sheet2.SubS2....and that does not work.

Any help is much appreciated.

Any cheap shots are surely warranted.   :)

thanks for your help!
0
Comment
Question by:BostonBob
3 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
Comment Utility
Here is the syntax:

Application.Run "sheet2.SubS2"
0
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 250 total points
Comment Utility
Hi,

You have to use the Sheet.CodeName

Maybe Sheet2.SubS2


Regards
0
 
LVL 15

Expert Comment

by:weinberk
Comment Utility
Attach the workbook.

Not sure why you'd have code attached to every sheet, but it should still work.  I prefer to put nearly everything in modules, but that's just a preference.

I also suggest prefixing public functions with public, just for readability.


If in sheet1 you have

public function DoThisFromSheetOne()
    msgbox "From sheet 1"
end function

Open in new window


and in sheet 2 you have
public function CallTheThingFromOne()
     DoThisFromSheetOne
end function

Open in new window


if you fun CallTheThingFromOne, it should display "From Sheet 1" in a message box.

Test that out for us?

If that doesn't work, or if you need more help, attach a sample.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now