Setting up VB.NET to work with Excel

Click on File and click on New Project. Under Visual basic,Select “Windows” and then select “Windows Form Application”. Give the project an appropriate name and select a location where you want to save this project.

When the project opens you will be presented with Form1. For the time being just lets create 3 buttons and name then “Create”,“Open”,“Cancel”. Give an appropriate heading to the form. Your form should look like this.

Now let’s set references for Excel in our project. For this click on the menu Project~~>Add Reference. You will be presented with a “Add Reference”-dialog Box. Navigate to the “COM” Tab and select the Microsoft Excel Object Library.

After setting the reference,double click on any of the button to open the Form1 Code Area and paste this line of code at the very top.

Imports Excel = Microsoft.Office.Interop.Excel
在.Net标签中可以找到
Microsoft.Office.Interop.Excel
Microsoft.Office.Tool.Excel
将这些都加入进来

Double-click on the third button “Cancel” and paste the code. This is how your code should look like.

Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button3_Click( ByVal sender As System. Object , ByVal e As System.EventArgs) Handles Button3.Click
Me .Close()
End Sub
End Class

And you are all set for automating Excel From VB.Net.

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...