Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Daz Daz is offline
external usenet poster
 
Posts: 7
Default Calling worksheet functions from within a module

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Calling worksheet functions from within a module

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a module [email protected] Excel Discussion (Misc queries) 1 September 28th 07 04:03 PM
Calling a Macro from module peter.thompson[_61_] Excel Programming 2 January 21st 06 11:14 PM
Calling worksheet module from other module. Michael Malinsky Excel Programming 2 December 14th 05 08:47 PM
Calling Worksheet SubProcs From Module Chris Villanueva Excel Programming 3 May 29th 04 02:53 AM
Calling VBA function that is in another module Jag Man Excel Programming 2 January 7th 04 03:37 AM


All times are GMT +1. The time now is 02:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"