ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Referring to Excel objects in VSTO (https://www.excelbanter.com/excel-programming/434649-referring-excel-objects-vsto.html)

Carlos Mallen

Referring to Excel objects in VSTO
 
Hi,

I'm using Visual Studio 2008 Professional Edition and Microsoft Office 2003
and working with an Excel 2003 Workbook template. The language I'm using is
Visual Basic.

When I'm in one of Excel's objects (like a worksheet), I can refer to
objects like in Me.Application.Workbooks(1). However, when I insert a new
module, I can't use the same syntax, because Visual Basic does not recognize
it. For what I know, I must use CType instead, but I don't know how to use
it.

Can anyone help me? It would be of great help if someone could give me an
example of how refer to a workbook, like in:

Dim wbk As Excel.Workbook
wbk = CType(x,Excel.Workbook)

Thanks in advance,

--
Carlos Mallen

Patrick Molloy[_2_]

Referring to Excel objects in VSTO
 
make sure that you have a refence set to the Microsoft Excel Library

dim xlApp as Excel.Application
dim xlWb as Excel.Workbook
dim xlWs as Excel.Worksheet
'instantiate excel
set xlApp = New Excel.Application
set xlWb = xlApp.Workbooks.Open("**path & file name**")
set xlWs = xlWb.Worksheets("Sheet1")

does this help?



"Carlos Mallen" wrote:

Hi,

I'm using Visual Studio 2008 Professional Edition and Microsoft Office 2003
and working with an Excel 2003 Workbook template. The language I'm using is
Visual Basic.

When I'm in one of Excel's objects (like a worksheet), I can refer to
objects like in Me.Application.Workbooks(1). However, when I insert a new
module, I can't use the same syntax, because Visual Basic does not recognize
it. For what I know, I must use CType instead, but I don't know how to use
it.

Can anyone help me? It would be of great help if someone could give me an
example of how refer to a workbook, like in:

Dim wbk As Excel.Workbook
wbk = CType(x,Excel.Workbook)

Thanks in advance,

--
Carlos Mallen


Carlos Mallen

Referring to Excel objects in VSTO
 
Thanks for your answer. I'm afraid it doesn't help because in Visual Basic
"Set" is not used to refer to objects. Although some things are similar, it
differs form Visual Basic for Applications, which is the language you used to
give me the example.

Thanks again,
--
Carlos Mallen


"Patrick Molloy" wrote:

make sure that you have a refence set to the Microsoft Excel Library

dim xlApp as Excel.Application
dim xlWb as Excel.Workbook
dim xlWs as Excel.Worksheet
'instantiate excel
set xlApp = New Excel.Application
set xlWb = xlApp.Workbooks.Open("**path & file name**")
set xlWs = xlWb.Worksheets("Sheet1")

does this help?



"Carlos Mallen" wrote:

Hi,

I'm using Visual Studio 2008 Professional Edition and Microsoft Office 2003
and working with an Excel 2003 Workbook template. The language I'm using is
Visual Basic.

When I'm in one of Excel's objects (like a worksheet), I can refer to
objects like in Me.Application.Workbooks(1). However, when I insert a new
module, I can't use the same syntax, because Visual Basic does not recognize
it. For what I know, I must use CType instead, but I don't know how to use
it.

Can anyone help me? It would be of great help if someone could give me an
example of how refer to a workbook, like in:

Dim wbk As Excel.Workbook
wbk = CType(x,Excel.Workbook)

Thanks in advance,

--
Carlos Mallen



All times are GMT +1. The time now is 11:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com