Create new excel file from VB .net app

cyates

New member
Joined
Aug 7, 2003
Messages
2
I was having some issues with a few of these examples. Im running VB.NET and Im trying to use the Excel 10.0 Object Library. It may be because its 10.0 and not 9.0, but anyway....

Here is the piece code that isnt working for me.

Code:
            .Range("A2:E2").Select()
            With EXL.Selection.Font
                .Name = "Verdana"
                .FontStyle = "Bold"
                .Size = 12
            End With

When I perform the select in my app, and try to referance the application object.selection I have no options. You know how the drop down list of functions comes down, the only function I would have for EXL.Selection is getType(). Ive found some ways around this, however, there are certain functions I have not figured out. Like setting the columns to autofit depending on the text in the cells.
 
this is because the members and methods of the Excel object are not available to the IDE (where you type); accessing those methods and members is done using late-binding - VB.NET lets you do late-binding and that is why you dont get a compile error when you debug - you would in C# with that code. Bascially the IDE can generate that drop down list of fucntions, variables, etc. of most things because those methods are exposed to the IDE; the methods for Excel Libraries are not; VB.NET assumes you are correct in saying that EXL has a member off it called Selection which has a member off of it call Font which has the properties of Name, FontStyle and Size - if it doesnt youll get a run-time error. The GetType() method is used to get the typeof(object) in this case, EXL... but I digress; until you feel like reading up of theories and the such or start working with C# or pretty much any other language besides VB that doesnt support late binding; open Excel, create a macro of what you want to do and copy and past it into your VB.NET and edit where needed... this is what I did before I learned about all of the stuff I just rambled to you about. And if you want to research that look up Late-Binding on MSDN and youll get a plethora of articles to thumb through...
 
Back
Top