当前位置: 代码迷 >> VBA >> vb.net操作EXCEL,为何设置了excelApp.Visible = False,excel仍然出现
  详细解决方案

vb.net操作EXCEL,为何设置了excelApp.Visible = False,excel仍然出现

热度:7299   发布时间:2013-02-26 00:00:00.0
vb.net操作EXCEL,为什么设置了excelApp.Visible = False,excel仍然出现
在我读取excel中的值之后,过一段时间才显示,不是立刻出来,大约5秒左右.



以下是我的所有代码了.
Private Sub BtOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOpenFile.Click
        Dim myStream As Stream = Nothing
        Try
            OpenFileDialog1.InitialDirectory = "c:\"
            OpenFileDialog1.Filter = "Excel files (*.xls;*.xlsx)|*.xls;*.xlsx|Csv files(*.csv)|*.csv|All files (*.*)|*.*"
            OpenFileDialog1.FilterIndex = 1
            OpenFileDialog1.RestoreDirectory = True

            If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                Try
                    myStream = OpenFileDialog1.OpenFile()
                    If (myStream IsNot Nothing) Then
                        Dim excelApp As Excel.Application = New Excel.Application ' CreateObject("Excel.Application")
                        excelApp.Visible = False
                        Dim excelWorkbook As Excel.Workbook
                        Dim excelSheet As Excel.Worksheet
                        Dim excelRange As Excel.Range   '定义工作区域
                        excelWorkbook = excelApp.Workbooks.Open(OpenFileDialog1.FileName)
                        excelApp.Workbooks.Add(True)

                        excelSheet = excelWorkbook.Worksheets(1)
                        excelSheet.Activate()
                        MsgBox(excelSheet.Cells(3, 1).value.ToString, MsgBoxStyle.Information, "xs")
                    End If
                Catch Ex As Exception
  相关解决方案