Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Calling a Sub in a Worksheet

This one is evading me. My macro opens another workbook and needs to call a
Public Sub located in a worksheet rather than a module. Is this even
possible? If the macro were in a module, things would work fine but that is
not the case here.

Any help will be greatly appreciated.
--
Best wishes,

Jim
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 772
Default Calling a Sub in a Worksheet

Why can't you put it in a module? you can leave it in the sub, and copy it as
a function in a module
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Jim Jackson" wrote:

This one is evading me. My macro opens another workbook and needs to call a
Public Sub located in a worksheet rather than a module. Is this even
possible? If the macro were in a module, things would work fine but that is
not the case here.

Any help will be greatly appreciated.
--
Best wishes,

Jim

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Calling a Sub in a Worksheet

Hi Jim,

This one seems to work for me. Opens a workbook then runs a public Sub named
"Test" that's in the Sheet1 code module.

Dim wb As Workbook

Set wb = Workbooks.Open("D:\Temp\Book1.xls")
Run wb.Name & "!Sheet1.Test"

This way also works:

Dim wb As Workbook

Set wb = Workbooks.Open("D:\Temp\Book1.xls")
wb.Sheets("Sheet1").Test



--
Hope that helps.

Vergel Adriano


"Jim Jackson" wrote:

This one is evading me. My macro opens another workbook and needs to call a
Public Sub located in a worksheet rather than a module. Is this even
possible? If the macro were in a module, things would work fine but that is
not the case here.

Any help will be greatly appreciated.
--
Best wishes,

Jim

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Calling a Sub in a Worksheet

Vergel,

Thank you very much. It works perfectly.
I could not make changes to the workbook itself since it is someone else's
property so calling the macro from my own macro was the only choice other
than manually clicking the button on the other one.

Thanks again, both of you for prompt answers and good help.
--
Best wishes,

Jim


"Vergel Adriano" wrote:

Hi Jim,

This one seems to work for me. Opens a workbook then runs a public Sub named
"Test" that's in the Sheet1 code module.

Dim wb As Workbook

Set wb = Workbooks.Open("D:\Temp\Book1.xls")
Run wb.Name & "!Sheet1.Test"

This way also works:

Dim wb As Workbook

Set wb = Workbooks.Open("D:\Temp\Book1.xls")
wb.Sheets("Sheet1").Test



--
Hope that helps.

Vergel Adriano


"Jim Jackson" wrote:

This one is evading me. My macro opens another workbook and needs to call a
Public Sub located in a worksheet rather than a module. Is this even
possible? If the macro were in a module, things would work fine but that is
not the case here.

Any help will be greatly appreciated.
--
Best wishes,

Jim

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 macros from worksheet to another NSNR Excel Discussion (Misc queries) 3 October 27th 07 01:49 PM
Calling another worksheet Patrick Simonds Excel Programming 2 December 9th 06 04:51 PM
vb.net calling worksheet by name Barnie[_2_] Excel Programming 1 April 28th 06 10:54 AM
Calling a worksheet via a codename Thierry Paradis Excel Programming 2 March 2nd 06 02:41 PM
Calling a different worksheet??? Tywardreath Excel Programming 3 December 14th 05 09:56 PM


All times are GMT +1. The time now is 12:06 AM.

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"