谁有读写excel的例子...给一个..谢谢

解决方案 »

  1.   

    參考
    http://expert.csdn.net/Expert/topic/2871/2871976.xml?temp=.7418177
      

  2.   

    运行时出错...complie error:
    User-defined type not defined
    为什么?
      

  3.   

    Private Sub cmdReadXLS_Click()
          Set dgData.DataSource = Read_Excel(App.Path & "\" & "test.xls")
          Set obj = Nothing
    End SubPublic Function Read_Excel _
             (ByVal sFile _
              As String) As ADODB.Recordset      On Error GoTo fix_err
          Dim rs As ADODB.Recordset
          Set rs = New ADODB.Recordset
          Dim sconn As String      rs.CursorLocation = adUseClient
          rs.CursorType = adOpenKeyset
          rs.LockType = adLockBatchOptimistic      sconn = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & sFile
          rs.Open "SELECT * FROM [sheet1$]", sconn
          Set Read_Excel = rs
          Set rs = Nothing
          Exit Function
    fix_err:
          Debug.Print Err.Description + " " + _
                      Err.Source, vbCritical, "Import"
          Err.Clear
    End Function
      

  4.   

    首先要引用库。dim objExcel as new excel.applicationprivate sub form_load()
        objexcel.workbooks.open "文件名"
        '弹出工作表的总数。
        msgbox objexcel.activeworkbook.sheets.count
        objexcel.activeworkbook.close false
        objexcel.quit
        set objexcel=nothing
    end sub
    http://b4018.xici.net(新任版主,欢迎光临。)
    提供:VB、VBA、Office二次开发免费技术支持;
    承接:各类项目开发,如MIS系统,WEB网站,中小型应用软件等等;CO.:Vansoft Workroom
    MSN:[email protected]
    Email:[email protected]
           [email protected]
    TEL:025-86685867(范,24H)
      

  5.   

    dim objExcel as new excel.application
    以上这句提示出错...
    complie error:
    User-defined type not defined
    ????????????????????????????????????????????
      

  6.   

    UP,UP,UP,UP,UP,UP,UP,UP,UP,UP,UP,UP,UP,UP,UP,UP为什么我试了上面的全都试不通啊...是不是我太笨了..我是初学的..没有系统学过VB,只是装了个软件就边拿边用,还下了一个教VB语法的电子书,就这样用..求救...急用
      

  7.   

    真的没人能回答我吗?我用:
    Set excel1 = CreateObject("excel.application")
    excel1.workbooks.Open "c:\bo.xls"
    excel1.Visible = True
    excel1.workbooks.Add
    excel1.Cells(1, 1).Value = "This is column A, row 1"
    可以打开,结果打开一个空的和bo.xls这两个EXCEL文件,而写只能写在空的那个excel上,怎样才能写在bo.xls这个EXCEL上,而不出现空的EXCEL