[英]VBA Excel SaveAs xlDBF4
StackOverflow 社區,
我最近在下面創建這個宏時遇到問題,關於如何從 excel 保存為 xlDBF4 和活動工作簿。我不明白為什么,但不起作用出現運行時錯誤,我已經嘗試使用 FileFormat:= 11 和文件格式:= xlDBF4
Sub SaveAsDBF()
Application.ScreenUpdating = False
Application.Calculation = xlManual
Application.DisplayAlerts = False
Application.EnableEvents = False
Dim strPath As String
strPath = "C:\"
strPath = strPath & ActiveSheet.Name & ".dbf"
ActiveWorkbook.SaveAs Filename:=strPath, FileFormat:=xlDBF4, _
CreateBackup:=False
'ActiveWorkbook.SaveAs Filename:=strPath, FileFormat:=11
End Sub
如果它絕對必須是一個 DBF 文件,那么最新的 Excel 的唯一解決方案是使用 ADODB 並執行查詢,確保你的辦公室 / Excel 是 32 位的,因為 DBF 的驅動程序只能在 32 位中工作。 參考Microsoft ActiveX Data Objects 6.1 Library
代碼示例來執行 DBF 查詢:
Dim conn As ADODB.Connection
Dim comm As ADODB.Command
Set conn = New ADODB.Connection
Set comm = New ADODB.Command
conn.ConnectionString = "Provider=Microsoft.Jet.OleDB.4.0;Extended Properties=dBASE IV;Data Source=C:\Temp"
comm.CommandText = "CREATE TABLE 201008 ([FirstName] String(50), [LastName] String(50))"
With conn
.Open
With comm
.ActiveConnection = conn
.Execute
End With
End With
conn.Close
Set conn = Nothing
Set comm = Nothing
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.