本文介绍了调用Excel 2007到Visual Basic 2005窗口窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Excell称为VB.继续在获取excel文件时出现错误.是因为我正在调用Excel 2007应用程序.当我打电话给Excel 2003时,它起作用了


I want to call Excell to VB. keep on giving a error when getting the excel file. Is it because i''m calling the Excel 2007 application. when I calling Excel 2003 it works


Dim xlApp As New Excel.Application
        Dim xcFileInfo As IO.FileInfo
        Dim xcFileDialog As New OpenFileDialog()
        Dim strFileName As String
        xcFileDialog.Filter = "Excel Spreadsheet Files!|*.xls"
        xcFileDialog.Title = "Select estimate in excel spreadsheet file!"
        If xcFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            xcFileInfo = New IO.FileInfo(xcFileDialog.FileName)
            xlApp = CreateObject("Excel.Application")
            strFileName = xcFileDialog.FileName
            'MessageBox.Show(strFileName)
            xlApp.Workbooks.Open(strFileName)
        End If
        xlApp.Visible = True
    End Sub

推荐答案

Dim objExcel As Microsoft.Office.Interop.Excel.Application
Dim objWB As Microsoft.Office.Interop.Excel.Workbook
Try
   objExcel = New Microsoft.Office.Interop.Excel.Application
   objWB = excel.Workbooks.Open("c:\\test.xls")
   objExcel.Visible = True
   objWB.Activate()
Catch ex As COMException
   MessageBox.Show("Error accessing Excel: " + ex.ToString())
End Try


这篇关于调用Excel 2007到Visual Basic 2005窗口窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 21:41