Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Where to Place Public Subs and Functions

Excel 2003. I have a multisheet workbook. Each sheet has many controls that
call some VBA code. Many of the subroutines and functions performed are
common to every sheet. I am presently duplicating the code for each sheet.
Where may I place these subs and functions so that they may become public,
and thus eliminate the duplication of code? I tried placing them in the
"code page" associated with "ThisWorkbook" and declaring them public. But
when I try to call these "public" routines from the individual sheets, they
cannot be found. What am I doing wrong?

By the way, what do you call the "code page" associated with inidivual
sheets and the "code page" associated with "ThisWorkbook"?
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Where to Place Public Subs and Functions

You could place all your common routines and functions as modules. Just
right click the Project in the VBE, and go Insert Module. Then you
should be able to call them.



*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Where to Place Public Subs and Functions

I tried to state my question in generic terms that would not need code
examples. Again the question is this:

How may I make a subroutine or function public in an Excel workbook. I want
to be able to call the subroutine or function from any of the worksheets. I
have tried putting the subroutines and function in the code space for
"ThisWorkbook" and declaring them Public. This does not work. I have
however been able to call the subroutine or function using:

Call ThisWorkbook.<subroutinename

However, I would like to be able to call these "public" routines without
having to prefix the call with "ThisWorkbook." Any help would be appreciated.

"Don Guillett" wrote:

As always, post YOUR code for comments. Saves time and effort

--
Don Guillett
SalesAid Software

"Chaplain Doug" wrote in message
...
Excel 2003. I have a multisheet workbook. Each sheet has many controls

that
call some VBA code. Many of the subroutines and functions performed are
common to every sheet. I am presently duplicating the code for each

sheet.
Where may I place these subs and functions so that they may become public,
and thus eliminate the duplication of code? I tried placing them in the
"code page" associated with "ThisWorkbook" and declaring them public. But
when I try to call these "public" routines from the individual sheets,

they
cannot be found. What am I doing wrong?

By the way, what do you call the "code page" associated with inidivual
sheets and the "code page" associated with "ThisWorkbook"?
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Where to Place Public Subs and Functions

Then just put in a module instead of ThisWorkbook module or sheet module

--
Don Guillett
SalesAid Software

"Chaplain Doug" wrote in message
...
I tried to state my question in generic terms that would not need code
examples. Again the question is this:

How may I make a subroutine or function public in an Excel workbook. I

want
to be able to call the subroutine or function from any of the worksheets.

I
have tried putting the subroutines and function in the code space for
"ThisWorkbook" and declaring them Public. This does not work. I have
however been able to call the subroutine or function using:

Call ThisWorkbook.<subroutinename

However, I would like to be able to call these "public" routines without
having to prefix the call with "ThisWorkbook." Any help would be

appreciated.

"Don Guillett" wrote:

As always, post YOUR code for comments. Saves time and effort

--
Don Guillett
SalesAid Software

"Chaplain Doug" wrote in

message
...
Excel 2003. I have a multisheet workbook. Each sheet has many

controls
that
call some VBA code. Many of the subroutines and functions performed

are
common to every sheet. I am presently duplicating the code for each

sheet.
Where may I place these subs and functions so that they may become

public,
and thus eliminate the duplication of code? I tried placing them in

the
"code page" associated with "ThisWorkbook" and declaring them public.

But
when I try to call these "public" routines from the individual sheets,

they
cannot be found. What am I doing wrong?

By the way, what do you call the "code page" associated with inidivual
sheets and the "code page" associated with "ThisWorkbook"?
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Where to Place Public Subs and Functions

Place a function or sub in a standard code module, and then in the controls
click event, call that (those) common functions.

A worksheet has a sheet class module, a workbook has a workbook class
module.

--
HTH

Bob Phillips

"Chaplain Doug" wrote in message
...
Excel 2003. I have a multisheet workbook. Each sheet has many controls

that
call some VBA code. Many of the subroutines and functions performed are
common to every sheet. I am presently duplicating the code for each

sheet.
Where may I place these subs and functions so that they may become public,
and thus eliminate the duplication of code? I tried placing them in the
"code page" associated with "ThisWorkbook" and declaring them public. But
when I try to call these "public" routines from the individual sheets,

they
cannot be found. What am I doing wrong?

By the way, what do you call the "code page" associated with inidivual
sheets and the "code page" associated with "ThisWorkbook"?
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Where to Place Public Subs and Functions

Thank you for the solution. God bless.

"Darrin Henshaw" wrote:

You could place all your common routines and functions as modules. Just
right click the Project in the VBE, and go Insert Module. Then you
should be able to call them.



*** Sent via Developersdex http://www.developersdex.com ***

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
Common Functions and Subs rbnorth Excel Discussion (Misc queries) 3 February 15th 06 10:07 PM
Called subs versus functions Neal Zimm Excel Programming 2 April 5th 05 06:43 AM
Public Functions As Worksheet Available Functions Steve King Excel Programming 3 February 12th 05 07:55 PM
Calling VBA add-in functions/subs from another Excel file. Bret Holle Excel Programming 1 September 17th 04 01:43 AM


All times are GMT +1. The time now is 06:28 PM.

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

About Us

"It's about Microsoft Excel"