回覆列表
  • 1 # 使用者2934567341832

    出現實時錯誤1004 應用程式定義或物件定義錯誤的原因是:

    在 Adodc中,該欄位的資料型別是圖片或多媒體等,而Excel不能識別,故出現上述錯誤。

    修改如下:

    intField) = Adodc1.Recordset(intField - 1).Value

    具體程式碼如下

    Private Sub Command2_Click()

    Dim priXLS As Excel.Application

    Dim priWorkbook As Excel.Workbook

    Dim priSheet As Excel.Worksheet

    Dim lngRow, lngRows, intField, intFields, lngID As Long

    Set priXLS = New Excel.Application

    Set priWorkbook = priXLS.Workbooks.Add

    Set priSheet = priXLS.Sheets(1)

    With priSheet

    intFields = Adodc1.Recordset.Fields.Count

    For intField = 1 To intFields

    .Cells(1, intField) = Adodc1.Recordset(intField - 1).Name

    Next

    Adodc1.Recordset.MoveLast

    Adodc1.Recordset.MoveFirst

    On Error Resume Next "防止欄位型別Excel不識而出錯!

    For lngID = 1 To Adodc1.Recordset.RecordCount

    For intField = 1 To intFields

    .Cells(lngID + 1, intField) = Adodc1.Recordset(intField - 1).Value

    Next

    Adodc1.Recordset.MoveNext

    Next

    End With

    priXLS.Visible = True

    End Sub

  • 中秋節和大豐收的關聯?
  • 一紙流年歌詞什麼意思?