sending to excell with VB

Hello all,
I'm not at all sure how to send information into an excell spreadsheet. I have all of the variables lined up etc, i just need to know how to insert them, and what I should import.
Any help is greatly appreciated!
Thanks so much
-Robert

P.S. If you could just point me to a tutorial, that would be fine too, however, I couldn't find any information about sending information online. Thanks



Answer this question

sending to excell with VB

  • Ketema Harris

    Hi All,
    thanks for that last post, It's a great start, however:
    I was wondering if there is any command that creates a realy excel spreadsheet In a nutshell, I've got some regexes in a foreach loop, and whenever the regex finds a match, I want that match to go into a new column. I've tried changing the number mid-runtime... So everytime that the foreach loop gets called, it adds a number to an integer, and then sending the data to that inter's column value... if that makes sense.
    However, all that does is make about 30 different spreadsheets, as opposed to all going into the same one.
    Again, sorry for such a nube question!
    Thanks in advance for any anwers, anything is greatly appreciated
    Sorry!  
    -Robert

  • Aron789

    What exactly do you mean with your question "I was wondering if there is any command that creates a realy excel spreadsheet "

    The example from rkimble you got earlier *is* creating a real Excel spreadsheet. The only thing you have to do to get a 'real' workbook is to save it when you are done:

    ex1.ActiveWorkbook.SaveAs("SomeFileName.xls")

    -= Maarten =-



  • ckm3812

    If you can get your hands on it (ie, MSDN subscription) the Visual Studio Tools for Office package is the best way to work with office programs (http://msdn.microsoft.com/office/tool/vsto/default.aspx).

    Next best thing is to use the Office PIAs (Primary Interop Assemblies), those can be downloaded - links can be found in the above site.

    If you have office installed on your development machine then you can just add a COM reference to the Excel x.x Object Library - but then you won't get much help from the IDE in using the library. But you can still acomplish a lot by referencing Excel 11.0 Object Library. For instance:

    Dim exl As New Microsoft.Office.Interop.Excel.Application
    exl.Workbooks.Add()

    Dim wrksht As
    Microsoft.Office.Interop.Excel.Worksheet
    wrksht = exl.ActiveWorkbook.ActiveSheet
    wrksht.Cells.Item(1, 1) =
    "TEST"

    exl.Visible =
    True

    This code opens Excel, creates a new Workbook, sets cell A1's text to the word "TEST" and then shows the application.

    See if the link and code snipit help you get started.

    GL!



  • sriesch

    Hey Robert, no problem on the questions... this is how we learn!

    You've probably just got too much code inside of your loop. This is the only code that belongs inside of the loop:

    wrksht.Cells.Item(1, 1) = "TEST"

    The rest should come before the loop starts (except the .Visible=True, that still goes last). Then, to move your values into a new column on each itteration of the loop, you use a variable instead of the hard-coded "1":

    wrksht.Cells.Item(1, x) = "TEST"

    Now you can keep incrementing the value of "x" and move each line into the next column.



  • sending to excell with VB