나는 엑셀 "응용 프로그램"사용자가/편집/등 어디 있습니다. 데이터. 준비가되면이 데이터를 내보내고 최종 산출물은 dBase 파일이어야합니다. Excel 2007에는 더 이상 Save dBase 기능이 없으므로 데이터를 Access Table로 내보내는 다음 코드를 만들었습니다.Excel VBA에서 dBase 파일로 액세스 테이블 내보내기?
내 VBA에서 Excel의 dBase 파일로 액세스 테이블을 전송할 수있는 방법이 있습니까? 아니면 Access 자체에서이 단계를 수행해야합니까?
나는 가능한 한 쉽게 수정하기 위해 모든 것을 Excel에서 유지하려고합니다. 어떤 도움을 주셔서 감사합니다. 가능한 경우 프로세스가 내 내보내기 프로세스와 자동으로 동기화 될 수 있으면 Access에서 수행하는 것이 좋습니다.
Sub Export()
Dim dbConnection As ADODB.Connection
Dim dbFileName As String
Dim dbRecordset As ADODB.Recordset
Dim xRow As Long, xColumn As Long
Dim LastRow As Long
'Go to the worksheet containing the records you want to transfer.
Worksheets("FeedSamples").Activate
'Determine the last row of data based on column A.
LastRow = Cells(Rows.Count, 1).End(xlUp).row
'Create the connection to the database.
Set dbConnection = New ADODB.Connection
'Define the database file name
dbFileName = "\\agfiles\public\ITSD_ApDev\James Scurlock\Personal Project Notes\FeedSampleResults.accdb"
'Define the Provider and open the connection.
With dbConnection
.Provider = "Microsoft.ACE.OLEDB.12.0;Data Source=" & dbFileName & _
";Persist Security Info=False;"
.Open dbFileName
End With
'Create the recordset
Set dbRecordset = New ADODB.Recordset
dbRecordset.CursorLocation = adUseServer
dbRecordset.Open Source:="ImportedData", _
ActiveConnection:=dbConnection, _
CursorType:=adOpenDynamic, _
LockType:=adLockOptimistic, _
Options:=adCmdTable
'Loop thru rows & columns to load records from Excel to Access.
'Assume row 1 is the header row, so start at row 2.
'ACCESS COLUMNS MUST BE NAMED EXACTLY THE SAME AS EXCEL COLUMNS
For xRow = 2 To LastRow
dbRecordset.AddNew
'Assume this is an 8-column (field) table starting with column A.
For xColumn = 1 To 69
dbRecordset(Cells(1, xColumn).value) = Cells(xRow, xColumn).value
Next xColumn
dbRecordset.Update
Next xRow
'Close the connections.
dbRecordset.Close
dbConnection.Close
'Release Object variable memory.
Set dbRecordset = Nothing
Set dbConnection = Nothing
'Optional:
'Clear the range of data (the records) you just transferred.
'Range("A2:H" & LastRow).ClearContents
MsgBox "Test"
Dim access As access.Application
Set access = "\\agfiles\public\ITSD_ApDev\James Scurlock\Personal Project Notes\FeedSampleResults.accdb"
access.DoCmd.OpenTable "ImportedData"
access.DoCmd.TransferDatabase acExport, "dBASE IV", "C:\", acTable, "ImportedData", "TEST.DBF"
DoCmd.Close acTable, "ImportedData"
'CREATE dBASE FILE!
End Sub
컴퓨터에 이전 버전의 Excel을 설치하고 이전 SaveAs DBase 기능을 사용할 수 있습니까? –
답장을 보내 주셔서 감사합니다. 그건 가능하지만 정부 업무의 어떤 형태로든 당신은 소프트웨어/하드웨어를 매번 업그레이드해야한다는 정책을 가지고 있습니다 ... :) 어쨌든 전체 dBase 아이디어는 Excel 양식으로 가기 위해 폐기되었습니다. 고정 폭 열 .txt 파일 나중에 참조 할 수 있도록 둘 다 작동했습니다! –
정부 정책에 따라 Office 사본을 업데이트하지만 데이터베이스는 업데이트하지 않도록하십시오. 데이터베이스가 아닌 Excel이 아닌 현대 데이터베이스 (mariadb, mysql, mssql, sqlite, 심지어 MS ACCESS)로 이동해야합니다. 그냥 생각. –