收到运行时错误 3436 创建文件失败

问题描述 投票:0回答:1

运行以下脚本时收到运行时错误 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
excel vba ms-access export
1个回答
0
投票

此版本包括 2 个重要更改:

  1. 根据 Warcupine
     丢弃了 
    DoCmd.TransferSpreadsheet 中的第六个参数 (Range
  2. )
  3. 根据 Shrotter
  4. 为输出文件提供了有效位置
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
© www.soinside.com 2019 - 2024. All rights reserved.