运行以下脚本时收到运行时错误 3436:
调试突出显示“DoCmd.TransferSpreadsheet acExport,acSpreadsheetTypeExcel9,_ td.Name,out_file,True,替换(td.Name,“dbo_”,“”)“
Private Sub getTBL_Click()
Dim td As DAO.TableDef, db As DAO.Database
Dim out_file As String
out_file = CurrentProject.Path & "C:\Users\Desktop\excel_out.xls"
Set db = CurrentDb()
For Each td In db.TableDefs
If Left(td.Name, 4) = "MSys" Then
'// do nothing -- skip
Else
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
td.Name, out_file, True, Replace(td.Name, "dbo_", "")
End If
Next
End Sub
此版本包括 2 个重要更改:
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim out_file As String
out_file = CurrentProject.Path & Chr(92) & "exel_out.xls"
Set db = CurrentDb()
For Each tdf In db.TableDefs
If Not (tdf.Name Like "Msys*") Then
'Debug.Print td.Name
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
tdf.Name, out_file, True
End If
Next