Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Accessing VSTO Workbook Methods
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Accessing VSTO Workbook Methods
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Accessing VSTO Workbook Methods
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VSTO - How to find all Pivot tables in the Workbook | Excel Programming | |||
Missing Excel Workbook Template - with VSTO SE installed | Excel Programming | |||
VSTO 2005 - How to use ThisWorkbook as an Excel.Workbook | Excel Programming | |||
Refreshing the data in a shared workbook with VSTO | Excel Programming | |||
Hidden workbook properties/methods | Excel Programming |