PC Review


Reply
Thread Tools Rate Thread

Accessing VSTO Workbook Methods

 
 
Ed White
Guest
Posts: n/a
 
      29th Jul 2008
I'm using VSTO with VB in VS 2008 and Excel 2007, and trying to understand
something basic. I've written some public methods in ThisWorkbook.vb, which
is the class created by VSTO with "Public Class ThisWorkbook". Suppose one
method I've writtine in the workbook is Public TestMethod. If I am writing
code in a worksheet, e.g. Sheet1.vb, and I want to access TestMethod, how do
I do it? TestMethod is under the ThisWorkbook class, and is not a shared
method. If I write ThisWorkbook.TestMethod, it says it's a non-shared member
and requires an object reference. Do I create an new instance of
ThisWorkbook in Sheet1, or will this confuse VSTO/Excel?

--
Ed
 
Reply With Quote
 
 
 
 
Ed White
Guest
Posts: n/a
 
      30th Jul 2008
To clarify and expand on the above, generally speaking, when I have methods
(i.e. subs) in ThisWorkbook and in different sheets, how do I call a method
in one sheet (or ThisWorkbook) from another sheet? If I make the subs
Shared, it works, except when I try to use "Me." in a shared method, it says
"'Me' is valid only within an instance method". So do I create instances of
all the sheets and the workbooks? It seems creating instances is strange in
VSTO.
--
Ed


"Ed White" wrote:

> I'm using VSTO with VB in VS 2008 and Excel 2007, and trying to understand
> something basic. I've written some public methods in ThisWorkbook.vb, which
> is the class created by VSTO with "Public Class ThisWorkbook". Suppose one
> method I've writtine in the workbook is Public TestMethod. If I am writing
> code in a worksheet, e.g. Sheet1.vb, and I want to access TestMethod, how do
> I do it? TestMethod is under the ThisWorkbook class, and is not a shared
> method. If I write ThisWorkbook.TestMethod, it says it's a non-shared member
> and requires an object reference. Do I create an new instance of
> ThisWorkbook in Sheet1, or will this confuse VSTO/Excel?
>
> --
> Ed

 
Reply With Quote
 
Ed White
Guest
Posts: n/a
 
      30th Jul 2008
I found the answer myself. For example, to access TestMethod in Sheet4, you
use
Globals.Sheet4.TestMethod

To access TestMethod in ThisWorkbook,
Globals.ThisWorkbook.TestMethod
--
Ed


"Ed White" wrote:

> To clarify and expand on the above, generally speaking, when I have methods
> (i.e. subs) in ThisWorkbook and in different sheets, how do I call a method
> in one sheet (or ThisWorkbook) from another sheet? If I make the subs
> Shared, it works, except when I try to use "Me." in a shared method, it says
> "'Me' is valid only within an instance method". So do I create instances of
> all the sheets and the workbooks? It seems creating instances is strange in
> VSTO.
> --
> Ed
>
>
> "Ed White" wrote:
>
> > I'm using VSTO with VB in VS 2008 and Excel 2007, and trying to understand
> > something basic. I've written some public methods in ThisWorkbook.vb, which
> > is the class created by VSTO with "Public Class ThisWorkbook". Suppose one
> > method I've writtine in the workbook is Public TestMethod. If I am writing
> > code in a worksheet, e.g. Sheet1.vb, and I want to access TestMethod, how do
> > I do it? TestMethod is under the ThisWorkbook class, and is not a shared
> > method. If I write ThisWorkbook.TestMethod, it says it's a non-shared member
> > and requires an object reference. Do I create an new instance of
> > ThisWorkbook in Sheet1, or will this confuse VSTO/Excel?
> >
> > --
> > Ed

 
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
Accessing Status Bar in VSTO add-in GP Microsoft Powerpoint 1 20th Apr 2009 04:26 PM
VSTO - How to find all Pivot tables in the Workbook Smugliy Microsoft Excel Programming 2 2nd Apr 2008 04:09 PM
Problem accessing ContactItems with VSTO 2005 timothy.goric@gmail.com Microsoft Outlook 1 6th Oct 2007 04:09 AM
Slow performance while accessing Outlook item fields using VSTO =?Utf-8?B?bWF4aW0=?= Microsoft Outlook Program Addins 3 16th Nov 2006 03:08 PM
VSTO 2005 - How to use ThisWorkbook as an Excel.Workbook =?Utf-8?B?ZGJLZW1w?= Microsoft Excel Programming 1 16th Oct 2006 09:40 AM


Features
 

Advertising
 

Newsgroups
 


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