Home All Groups Group Topic Archive Search About

Where is ThisWorkbook.Sheets("xx") ?? Unable to resolve 'ThisWorkbook' :: Interop to Excel

Author
14 Mar 2006 11:51 PM
Eric W
I am converting an EXCEL VBA application to Visual Basic (2003).

I am not having much luck finding how to convert statements containing
references to things like ThisWorkbook.Sheets("sheetname").

I am not using Visual Studio Tools (which may be my problem, tho I would
think that I don't really need the templates --- or do I??)

Eric


(Soory for the repost - I noticed a typo in my Subject)

Author
15 Mar 2006 12:38 AM
Homer J Simpson
"Eric W" <nob***@wzone.com> wrote in message
news:pan.2006.03.14.23.51.25.384915@wzone.com...

>I am converting an EXCEL VBA application to Visual Basic (2003).
>
> I am not having much luck finding how to convert statements containing
> references to things like ThisWorkbook.Sheets("sheetname").
>
> I am not using Visual Studio Tools (which may be my problem, tho I would
> think that I don't really need the templates --- or do I??)

Have you tried recording macros and seeing what the code looks like?
Author
15 Mar 2006 11:32 AM
Carlos J. Quintero [VB MVP]
ThisWorkBook can be used inside VBA because it is an intrinsic object, but
from outside you need to retrieve the WorkBook from the Application
instance, usingh objApplication.ActiveWorkbook or
objApplication.WorkBooks.Item(xxx)

Which is your specific problem?

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com


Show quoteHide quote
"Eric W" <nob***@wzone.com> escribió en el mensaje
news:pan.2006.03.14.23.51.25.384915@wzone.com...
>I am converting an EXCEL VBA application to Visual Basic (2003).
>
> I am not having much luck finding how to convert statements containing
> references to things like ThisWorkbook.Sheets("sheetname").
>
> I am not using Visual Studio Tools (which may be my problem, tho I would
> think that I don't really need the templates --- or do I??)
>
> Eric
>
>
> (Soory for the repost - I noticed a typo in my Subject)
Author
16 Mar 2006 6:50 PM
Eric W
In my Basic.Net code, I figured out that I can resolve the Application
references with the statements:


Dim ExcelWorkbook = Excel.Workbook
Dim ExcelWorksheet = Excel.ApplicationClass

That made the syntax errors go away. BUT if I try to do something
really simple like MsgBox(Application.Cells("A1")

I get an #Value! error in Excel.

Which when I think about it, I'm not assigning ExcelWorkbook nor
ExcelWorksheet to anything, so it's no wonder why I get an error.

So.......

How do I reference to actual Excel Object? (So that I can refer to cells,
ranges, and use Excel's functions.)

(My code didn't start Excel; Excel called me).


I don't have the Visual Studio Tools for Office (maybe I should buy it???)



On Wed, 15 Mar 2006 12:32:39 +0100, Carlos J. Quintero [VB MVP] wrote:

Show quoteHide quote
> ThisWorkBook can be used inside VBA because it is an intrinsic object, but
> from outside you need to retrieve the WorkBook from the Application
> instance, usingh objApplication.ActiveWorkbook or
> objApplication.WorkBooks.Item(xxx)
>
> Which is your specific problem?
Author
21 Mar 2006 11:13 AM
Carlos J. Quintero [VB MVP]
Hi,

> (My code didn't start Excel; Excel called me).
> I don't have the Visual Studio Tools for Office (maybe I should buy it???)

AFAIK, there are three ways to interact with Excel:

- Your code starts Excel externally
- You are creating an add-in for Excel using .NET.
- You are using VSTO to extend Excel instead of using VBA.

So, which is your case? How does Excel "call" you?

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com