Add in blows up! Author disavows responsibility

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,

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.
 
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.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top