PC Review


Reply
Thread Tools Rate Thread

Calling a Sub in a Worksheet

 
 
=?Utf-8?B?SmltIEphY2tzb24=?=
Guest
Posts: n/a
 
      23rd Jul 2007
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 With Quote
 
 
 
 
=?Utf-8?B?Sm9obiBCdW5keQ==?=
Guest
Posts: n/a
 
      23rd Jul 2007
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

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      23rd Jul 2007
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 With Quote
 
=?Utf-8?B?SmltIEphY2tzb24=?=
Guest
Posts: n/a
 
      23rd Jul 2007
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 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 a sub on another worksheet mooresk257 Microsoft Excel Programming 5 27th May 2010 10:32 PM
calling a worksheet function from another worksheet in same workbo Liz Microsoft Excel Programming 5 23rd Jun 2008 06:16 PM
Calling another worksheet Patrick Simonds Microsoft Excel Programming 2 9th Dec 2006 04:51 PM
vb.net calling worksheet by name Barnie Microsoft Excel Programming 1 28th Apr 2006 10:54 AM
Calling a different worksheet??? =?Utf-8?B?VHl3YXJkcmVhdGg=?= Microsoft Excel Programming 3 14th Dec 2005 09:56 PM


Features
 

Advertising
 

Newsgroups
 


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