我相信我有一个简单的问题,但此刻我的想法完全令人难以置信。我不能让任何一个代码不立即给我一个语法错误。
Private Sub btnManualExportInvoicing_Click()
Dim Filepath As String
Filepath = CurrentProject.Path & "\Invoicing"
If Len(Dir(Filepath, vbDirectory)) = 0 Then
MkDir Filepath
End If
DoCmd.TransferSpreadsheet (acExport, acSpreadsheetTypeExcel12, _
"tblInvoicing", Filepath & "\Invoicing info & Format(date, "yyyy-mm-dd")&".xlsx" ,,)
DoCmd.TransferSpreadsheet (1, 9, "tblInvoicing", Filepath & "\Invoicing info
& Format(date, "yyyy-mm-dd")&".xlsx" ,,)
DoCmd.OutputTo (0, "tblInvoicing", acFormatXLSX, Filepath & "\Invoice Info"
& , False,)
End Sub
所有这些Do.cmd类型都给我一个语法错误(突出显示为红色)。我错过了什么?
答案 0 :(得分:0)
VBA需要各种语法规则,特别是对于whitepsace和换行符,编译器会在您离开有问题的行时立即引发错误。适用于您的情况的此类规则包括:
&
DoCmd.TransferSpreadsheet()
,除非将其分配给变量set obj = DoCmd.TransferSpreadsheet()
因此,请考虑以下调整:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "tblInvoicing", _
Filepath & "\Invoicing info" & Format(date, "yyyy-mm-dd") & ".xlsx"
DoCmd.TransferSpreadsheet 1, 9, "tblInvoicing", _
Filepath & "\Invoicing info" & Format(date, "yyyy-mm-dd") & ".xlsx"
DoCmd.OutputTo 0, "tblInvoicing", acFormatXLSX, _
Filepath & "\Invoice Info" & Format(date, "yyyy-mm-dd") & ".xlsx", False
答案 1 :(得分:0)
调整引号和导出类型(以匹配文件扩展名)并删除括号:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml,"tblInvoicing", _
Filepath & "\Invoicing info " & Format(Date, "yyyy-mm-dd") & ".xlsx"