ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add in blows up! Author disavows responsibility (https://www.excelbanter.com/excel-programming/323210-add-blows-up-author-disavows-responsibility.html)

Michael Conroy

Add in blows up! Author disavows responsibility
 
Hi folks...

All I want to do is create a COM VB.NET addin for Excel. I used the
Wizard. I can create a spiffy CommandBar with buttons and everything. What
I CAN'T do is reference the silly applicationObject. No matter WHAT I do...
Cells, Range, etc... I can't even get an ActiveWorkbook returned. Can
anyone point me to a stupid simple example showing how to write a value to a
cell using VB.NET as an Addin? Plenty of samples show how to invoke Excel
from an app, but I want my app to live inside Excel as an addin.

Thanks,
M.

Tom Ogilvy

Add in blows up! Author disavows responsibility
 
http://support.microsoft.com/default.aspx?kbid=302896
How To Build an Office COM Add-in by Using Visual Basic .NET

--
Regards,
Tom Ogilvy



"Michael Conroy" wrote in message
...
Hi folks...

All I want to do is create a COM VB.NET addin for Excel. I used the
Wizard. I can create a spiffy CommandBar with buttons and everything.

What
I CAN'T do is reference the silly applicationObject. No matter WHAT I

do...
Cells, Range, etc... I can't even get an ActiveWorkbook returned. Can
anyone point me to a stupid simple example showing how to write a value to

a
cell using VB.NET as an Addin? Plenty of samples show how to invoke Excel
from an app, but I want my app to live inside Excel as an addin.

Thanks,
M.




Michael Conroy

Add in blows up! Author disavows responsibility
 
Tom,

Thanks for the post. Sadly - I've been there. In fact, that's where I
started to build my little add-in framework. What the article *doesn't*
address (hence the origin of the question), is how to tickle a cell in Excel.
It really shouldn't be difficult from within the add-in - in fact, I would
think it'd be a snap. However, as my first post alluded, it just ain't
happenin'.

Cheers,
M.


Tim Williams

Add in blows up! Author disavows responsibility
 
So when your addin is loaded does the OnConnection event fire? From
Tom's reference that should give you a handle to the "host application
object": from this you should be able to get a reference to workbooks
etc. Are you not getting this object passed?

Do you have any code you can show ?

Tim.


"Michael Conroy" wrote in
message ...
Hi folks...

All I want to do is create a COM VB.NET addin for Excel. I used
the
Wizard. I can create a spiffy CommandBar with buttons and
everything. What
I CAN'T do is reference the silly applicationObject. No matter WHAT
I do...
Cells, Range, etc... I can't even get an ActiveWorkbook returned.
Can
anyone point me to a stupid simple example showing how to write a
value to a
cell using VB.NET as an Addin? Plenty of samples show how to invoke
Excel
from an app, but I want my app to live inside Excel as an addin.

Thanks,
M.




Michael Conroy

Add in blows up! Author disavows responsibility
 
Tim,

Thanks for the reply...

The OnConnection event if firing fine. My problem was an inability to get
to any Workbook or Worksheet. I was using CType to get the appobject to
become type Excel.Application. I thought that would be fine. When my first
approach didn't work trying to get to a specific workbook by ordinal, I set a
breakpoint and tried to do everything from the Command window - this approach
is great for trying out one-liners. In every case, I'd get a COMInterop
failure.

Honestly, I don't know what I did to fix it... but ultimately, I was able to
get some results by Dim'ing the hell out of everything...

To wit:

Dim wb as Excel.Workbook = applicationObject.Workbooks(1)
Dim ws as Excel.Worksheet = wb.Worksheets("Test") ' or Worksheets(1)

CType(ws.Cells(1, 1), Excel.Range).Value="Boy is this cumbersome"

Nevertheless, I SWEAR to you that the first two statements above didn't work
initially. I guess waving the dead chicken over the keyboard did the trick.

Thanks for taking the time...
M.

"Tim Williams" wrote:

So when your addin is loaded does the OnConnection event fire? From
Tom's reference that should give you a handle to the "host application
object": from this you should be able to get a reference to workbooks
etc. Are you not getting this object passed?

Do you have any code you can show ?

Tim.


"Michael Conroy" wrote in
message ...
Hi folks...

All I want to do is create a COM VB.NET addin for Excel. I used
the
Wizard. I can create a spiffy CommandBar with buttons and
everything. What
I CAN'T do is reference the silly applicationObject. No matter WHAT
I do...
Cells, Range, etc... I can't even get an ActiveWorkbook returned.
Can
anyone point me to a stupid simple example showing how to write a
value to a
cell using VB.NET as an Addin? Plenty of samples show how to invoke
Excel
from an app, but I want my app to live inside Excel as an addin.

Thanks,
M.





Tim Williams

Add in blows up! Author disavows responsibility
 
.....I always keep a chicken handy for just that purpose

Tim.


"Michael Conroy" wrote in
message ...
Tim,

Thanks for the reply...

The OnConnection event if firing fine. My problem was an inability
to get
to any Workbook or Worksheet. I was using CType to get the
appobject to
become type Excel.Application. I thought that would be fine. When
my first
approach didn't work trying to get to a specific workbook by
ordinal, I set a
breakpoint and tried to do everything from the Command window - this
approach
is great for trying out one-liners. In every case, I'd get a
COMInterop
failure.

Honestly, I don't know what I did to fix it... but ultimately, I was
able to
get some results by Dim'ing the hell out of everything...

To wit:

Dim wb as Excel.Workbook = applicationObject.Workbooks(1)
Dim ws as Excel.Worksheet = wb.Worksheets("Test") ' or
Worksheets(1)

CType(ws.Cells(1, 1), Excel.Range).Value="Boy is this cumbersome"

Nevertheless, I SWEAR to you that the first two statements above
didn't work
initially. I guess waving the dead chicken over the keyboard did
the trick.

Thanks for taking the time...
M.





All times are GMT +1. The time now is 09:00 AM.

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