如何在VB中调用EXCEL打开*.XLS文件?

解决方案 »

  1.   

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Sub Form_Load()ShellExecute Me.hWnd, "open", "C:\User.xls", vbNullString, vbNullString, SW_SHOWEnd Sub
      

  2.   

    我觉得用个ado,加上grid就可以了。
      

  3.   

    Set x = CreateObject("Excel.Application")
                x.Workbooks.Open (Execl文件名)
                x.Visible = True
      

  4.   

    If MsgBox("要导入数据吗?", vbYesNo, "需要吗?") = vbNo Then Exit Sub
    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlWorksheet As Excel.Worksheet
    Dim xlActiveSheet As Excel.Worksheet
    Dim strtemp(28), strFieldName(28) As String
    Dim tmp_line As Integer
    strtemp(1) = "A"
    strtemp(2) = "B"
    strtemp(3) = "C"
    strtemp(4) = "D"
    strtemp(5) = "E"
    strtemp(6) = "F"
    strtemp(7) = "G"
    strtemp(8) = "H"
    strtemp(9) = "I"
    strtemp(10) = "J"
    strtemp(11) = "K"
    strtemp(12) = "L"
    strtemp(13) = "M"
    strtemp(14) = "N"
    strtemp(15) = "O"
    strtemp(16) = "P"
    strtemp(17) = "Q"
    strtemp(18) = "R"
    strtemp(19) = "S"
    strtemp(20) = "T"
    strtemp(21) = "U"
    strtemp(22) = "V"
    strtemp(23) = "W"
    strtemp(24) = "X"
    strtemp(25) = "Y"
    strtemp(26) = "Z"
    strtemp(27) = "AA"
    strtemp(28) = "AB"    
    Set xlApp = New Excel.Application
    Set xlBook = xlApp.Workbooks.Open(App.Path & "\数据库.xls")
    Set xlWorksheet = xlBook.Worksheets("sheet1")
    Set xlActiveSheet = xlApp.ActiveSheet'读内容
    tmp_line = 2Do
        tttmp = ""
        For i = 1 To 28
                
            strFieldName(i) = Trim(xlBook.Worksheets("sheet1").Range(strtemp(i) & tmp_line).Value)
            strFieldName(i) = Replace(strFieldName(i), "'", "''")
            tttmp = tttmp & strFieldName(i)    Next i
        
        DoEvents    If tttmp <> "" Then    Else    End If    tmp_line = tmp_line + 1Loop Until Trim(tttmp) = ""    '一共有多少行
    'MsgBox xlActiveSheet.UsedRange.Rows.Count - 1
        
    xlBook.Close
    Set xlBook = Nothing
    Set xlApp = Nothing
    Set xlWorksheet = Nothing
      

  5.   

    引用Microsoft Excel x.0(版本号) Object library    Dim ExlApp As Excel.Application
        Dim xlsWorkBook As Excel.Workbook
        Dim xlsSheet As Excel.Worksheet    Set xlsWorkBook = ExlApp.Workbooks.Open("e:\a.xls")
        Set xlsSheet = xlsWorkBook.Worksheets(1)
        ExlApp.Visible = True