qq_34300825
qq_34300825
2019-05-05 15:06

VB.net调用Excel两个问题

5
  • visual studio
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim i As Integer
        xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
        xlApp.Visible = True '设置EXCEL可见
        xlBook = xlApp.Workbooks.Open("E:\bb.xlsm") '打开EXCEL工作簿
        xlSheet = xlBook.Worksheets(1) '打开EXCEL工作表
        xlSheet.Activate() '激活工作表xlSheet.Activate()
        i = 1
        Do Until xlSheet.Cells(i, 1) = ""
            i = i + 1
        Loop
        xlSheet.Cells(i, 1) = TextBox1.Text '给单元格1行驶列赋值xlSheet.Cells(1, 1) & 
        xlBook.RunAutoMacros(Excel.XlRunAutoMacro.xlAutoOpen) '运行EXCEL中的启动宏
        xlBook.Save()
        xlBook.RunAutoMacros(Excel.XlRunAutoMacro.xlAutoClose) '执行EXCEL关闭宏
        xlBook.Close(True) '关闭EXCEL工作簿
        xlApp.Save()
        xlApp.Quit() '关闭EXCEL
        xlSheet = Nothing
        xlBook = Nothing
        xlApp = Nothing '释放EXCEL对象
        MsgBox("保存成功")
    End Sub!
        [图片说明](https://img-ask.csdn.net/upload/201905/05/1557039717_488488.png)![图片说明](https://img-ask.csdn.net/upload/201905/05/1557039769_163946.png)


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐