Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 504
Default call Module from MS Excel Object - Probably very easy VB questions

Hi
I created a Module called "Test" ie sub Test( ). It is a very simple macro
that sorts a few tables in a single sheet

I added the same code to a Workbook open function ie Private Sub
Workbook_Open( ) which works fine

However I want it so that I update the code in one place ie sub Test ( ), I
simply point to this from whereever I want - this way I only update once and
don't need to ensure the code is always the same.

Background is I want to force the sort in many instances eg manually, when I
open the workbook, when I activate a new sheet etc

thanks in advance




--
Kevin
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default call Module from MS Excel Object - Probably very easy VB questions

First create a public sub in a standard module:

Public Sub hithere()
MsgBox ("hi there")
End Sub

Then from workbook or worksheet event code:

Private Sub Worksheet_Change(ByVal Target As Range)
Call hithere
End Sub

--
Gary''s Student - gsnu200763


"Kevin" wrote:

Hi
I created a Module called "Test" ie sub Test( ). It is a very simple macro
that sorts a few tables in a single sheet

I added the same code to a Workbook open function ie Private Sub
Workbook_Open( ) which works fine

However I want it so that I update the code in one place ie sub Test ( ), I
simply point to this from whereever I want - this way I only update once and
don't need to ensure the code is always the same.

Background is I want to force the sort in many instances eg manually, when I
open the workbook, when I activate a new sheet etc

thanks in advance




--
Kevin

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 504
Default call Module from MS Excel Object - Probably very easy VB quest

I get a Compile error: Expected variable or procedure, not module

any idea what i have done wrong?
--
Kevin


"Gary''s Student" wrote:

First create a public sub in a standard module:

Public Sub hithere()
MsgBox ("hi there")
End Sub

Then from workbook or worksheet event code:

Private Sub Worksheet_Change(ByVal Target As Range)
Call hithere
End Sub

--
Gary''s Student - gsnu200763


"Kevin" wrote:

Hi
I created a Module called "Test" ie sub Test( ). It is a very simple macro
that sorts a few tables in a single sheet

I added the same code to a Workbook open function ie Private Sub
Workbook_Open( ) which works fine

However I want it so that I update the code in one place ie sub Test ( ), I
simply point to this from whereever I want - this way I only update once and
don't need to ensure the code is always the same.

Background is I want to force the sort in many instances eg manually, when I
open the workbook, when I activate a new sheet etc

thanks in advance




--
Kevin

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default call Module from MS Excel Object - Probably very easy VB quest

The problem is likely that your code module (which contains the procedure)
has the same name as a procedure. Change the name of the module or the name
of the procedure.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Kevin" wrote in message
...
I get a Compile error: Expected variable or procedure, not module

any idea what i have done wrong?
--
Kevin


"Gary''s Student" wrote:

First create a public sub in a standard module:

Public Sub hithere()
MsgBox ("hi there")
End Sub

Then from workbook or worksheet event code:

Private Sub Worksheet_Change(ByVal Target As Range)
Call hithere
End Sub

--
Gary''s Student - gsnu200763


"Kevin" wrote:

Hi
I created a Module called "Test" ie sub Test( ). It is a very simple
macro
that sorts a few tables in a single sheet

I added the same code to a Workbook open function ie Private Sub
Workbook_Open( ) which works fine

However I want it so that I update the code in one place ie sub Test
( ), I
simply point to this from whereever I want - this way I only update
once and
don't need to ensure the code is always the same.

Background is I want to force the sort in many instances eg manually,
when I
open the workbook, when I activate a new sheet etc

thanks in advance




--
Kevin


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 504
Default call Module from MS Excel Object - Probably very easy VB quest

spot on - thanks
--
Kevin


"Chip Pearson" wrote:

The problem is likely that your code module (which contains the procedure)
has the same name as a procedure. Change the name of the module or the name
of the procedure.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Kevin" wrote in message
...
I get a Compile error: Expected variable or procedure, not module

any idea what i have done wrong?
--
Kevin


"Gary''s Student" wrote:

First create a public sub in a standard module:

Public Sub hithere()
MsgBox ("hi there")
End Sub

Then from workbook or worksheet event code:

Private Sub Worksheet_Change(ByVal Target As Range)
Call hithere
End Sub

--
Gary''s Student - gsnu200763


"Kevin" wrote:

Hi
I created a Module called "Test" ie sub Test( ). It is a very simple
macro
that sorts a few tables in a single sheet

I added the same code to a Workbook open function ie Private Sub
Workbook_Open( ) which works fine

However I want it so that I update the code in one place ie sub Test
( ), I
simply point to this from whereever I want - this way I only update
once and
don't need to ensure the code is always the same.

Background is I want to force the sort in many instances eg manually,
when I
open the workbook, when I activate a new sheet etc

thanks in advance




--
Kevin


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
Inserting a MS Word object into an Excel spreadsheet (2 questions) Phrank Excel Worksheet Functions 1 December 28th 07 02:22 PM
Dividing in excel easy questions HELP PLEASE HELP Excel Discussion (Misc queries) 3 November 9th 07 08:07 PM
macro in excel to call a access module to run. [email protected] Excel Discussion (Misc queries) 0 April 23rd 07 08:59 PM
to call procedure in a worksheet in a module CAPTGNVR Excel Discussion (Misc queries) 4 January 30th 07 09:39 PM
Couple of hopefully easy questions TeddyTash Excel Worksheet Functions 4 September 15th 05 10:55 AM


All times are GMT +1. The time now is 08:25 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"