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

  • Thread starter Thread starter Eric W
  • Start date Start date
E

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)
 
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?
 
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
 
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???)
 
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
 
Back
Top