Setting up VB.NET to work with Excel

2 篇文章 0 订阅

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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值