![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Sep 2002
Location: Bristol
Posts: 71
|
I've written some code in ms excel objects, for a worksheet, and want to call code for another objects worksheet at the end. I've tried
Sub Sheet1() (code) Call Sheet2 End Sub ................ Sub Sheet2() (code) End Sub but when i try to run it it says there's an expected function or variable. it works when i use modules but for this code i need it in the worksheet. any suggestions? |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 3,876
|
Hi mcgew,
I don't believe the scope rules in Excel permit calling a procedure that is within a worksheet's event code module from any other module. The way around this is to put the common code you want to apparently use from both modules in a standard macro module (as you mentioned). So your example would look like: Sub Sheet1() (code) Call CommonCode End Sub ................ Sub Sheet2() Call CommonCode End Sub ---------------- 'inside standard macro module Sub CommonCode() . . End Sub So Sub Sheet1 can be called from events within sheet1's event code module, Sub Sheet 2 can be called from events within sheet2's event code module, and the two can share the common code.
__________________
Keep Excelling. Damon VBAexpert Excel Consulting (My other lives: http://members.tripod.com/playitagaindamon , http://community.webshots.com/user/piadamon ) |
|
|
|
|
|
#3 |
|
Join Date: Sep 2002
Location: Bristol
Posts: 71
|
Thanks for your help.
Grace :D |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|