Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have written an add in for Excel in VBA, but I would now like to convert it to VB.Net. I have been looking at VB.net tutorials and I read this but I am still confused on getting started.

I have started a new Excel Add-In Project and have this code:

Public Sub Test1()
    Dim oExcel As Object
    Dim oBook As Object
    Dim oSheet As Object

    'Start a new workbook in Excel.
    oExcel = CreateObject("Excel.Application")
    oBook = oExcel.Workbooks.Add

    oSheet = oBook.Worksheets(1)

    oSheet.Cells(1, 1) = "HEY!"

End Sub

This starts up Excel in a new window and I get the standard Excel new worksheet or template prompt, and when I choose blank workbook the "HEY!" does not appear.

Also, I want this to be an add in that works with the current active sheet, not starting a new one. Am I going about this wrong?

Edit: I don't see how this question is too broad tbh. I have provided code that I have basically copied from a tutorial and said exactly what the code is doing, and what it should be doing. Its certainly a beginner question, but not too broad imo. Please let me know what I can do to fix it.

share|improve this question

closed as too broad by me how, Yan Sklyarenko, Vasili Syrakis, hutchonoid, Kuf May 29 at 11:54

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Look up VSTO (Visual Studio Tools for Office) –  me how May 29 at 7:09

1 Answer 1

Instead of:

oSheet.Cells(1, 1) = "HEY!"

Try:

oSheet.Cells(1, 1).Value = "HEY!"

For more info, see here.

share|improve this answer
    
I tried this and I got the same result. I see that I need to add the property in there though. But I even tried copying the first 12 lines from the first sub in the link you provided and I still got the same result. Also, is this what I need to be doing if I want to create an add-in instead of an app that opens Excel and creates a new workbook? –  Adam12344 May 29 at 15:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.