PC Review


Reply
Thread Tools Rate Thread

Calling worksheet functions from within a module

 
 
Daz
Guest
Posts: n/a
 
      29th Nov 2006
hi all.

I'm wondering how I can call a 'public' worksheet function from within
a module, or even from a seperate worksheet.

Say I have a function in a worksheet that sets the background colour of
range of cells to clear, and I have a button on a seperate worksheet,
and on the buttons onClick event I want it to run that function.

Help appreciated.

Darragh

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QWxvaw==?=
Guest
Posts: n/a
 
      29th Nov 2006
Hi Daz,
This is simple. However, it is not the recommended practice. The usual
practice is to place all the common functions in a module.

First create a function shown below in Sheet1

Public Function abc(ByRef ws As Worksheet)
ws.Range("A1:A10").Interior.ColorIndex = 54
End Function

Next create the following function in Sheet2
Public Function Def()
Sheet1.abc Worksheets(3)
End Function

If you call Def() through some method, it will in turn call the Abc()
function in Sheet1. The trick is to use the name of the programmatic name of
the Sheet. Infact once you type the Sheet1. the "abc" will be shown
automatically by the intellisense.

You can put the same function Def() in a module and the effect will be the
same.


"Daz" wrote:

> hi all.
>
> I'm wondering how I can call a 'public' worksheet function from within
> a module, or even from a seperate worksheet.
>
> Say I have a function in a worksheet that sets the background colour of
> range of cells to clear, and I have a button on a seperate worksheet,
> and on the buttons onClick event I want it to run that function.
>
> Help appreciated.
>
> Darragh
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling functions in a global module frozensnow Microsoft ASP .NET 1 12th Apr 2007 05:44 PM
Calling worksheet module from other module. Michael Malinsky Microsoft Excel Programming 2 14th Dec 2005 08:47 PM
Extend the calling of Custom Functions by including Module name =?Utf-8?B?SmFSYQ==?= Microsoft Access Queries 2 10th Mar 2005 05:31 PM
Calling Worksheet SubProcs From Module Chris Villanueva Microsoft Excel Programming 3 29th May 2004 02:53 AM
Calling functions on a Form Class Object from a Module Sullivan Microsoft Access VBA Modules 3 14th Jul 2003 09:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:43 PM.