Merge 2 database file into 1 database file

Hasegawa

New Member
Joined
Oct 31, 2018
Messages
10
Dear Master(s),

I want to merge 2 database file into 1 database :

Code:
Sub SyncFromDatabase()


Application.ScreenUpdating = False
LastLocalChange = Sheet1.Range("B12").Value
    DbFile = "D:\DepositData.xlsx" 'Customer Database Location
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    On Error GoTo FileMissing
    Set objFile = objFSO.GetFile(DbFile)
If objFile.DateLastModified > LastLocalChange Then 'Database Change was made, update Local Database
    'Check Last Database Update
    Sheet2.Range("A2:P9999").ClearContents 'Clear existing data
    On Error Resume Next
    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordset = CreateObject("ADODB.Recordset")
    objConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & "D:\DepositData.xlsx" & ";Extended Properties=""Excel 12.0 Xml;HDR=Yes;IMEX=0"";"
    objRecordset.Open "Select * FROM [ShptDb$]", objConnection
    Sheet2.Range("A2").CopyFromRecordset objRecordset
    objRecordset.Close
    objConnection.Close
End If
Exit Sub
FileMissing:
MsgBox "Please browse for the database file"
BrowseForFile




End Sub

I want to merge D:\DepositData.xlsx and D:\DepositData.xlsx1 so after I syn it, I can see all data from both database. Thanks in advance all masters.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Sorry merge with D:\DepositData1.xlsx
Dear Master(s),

I want to merge 2 database file into 1 database :

Code:
Sub SyncFromDatabase()


Application.ScreenUpdating = False
LastLocalChange = Sheet1.Range("B12").Value
    DbFile = "D:\DepositData.xlsx" 'Customer Database Location
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    On Error GoTo FileMissing
    Set objFile = objFSO.GetFile(DbFile)
If objFile.DateLastModified > LastLocalChange Then 'Database Change was made, update Local Database
    'Check Last Database Update
    Sheet2.Range("A2:P9999").ClearContents 'Clear existing data
    On Error Resume Next
    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordset = CreateObject("ADODB.Recordset")
    objConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & "D:\DepositData.xlsx" & ";Extended Properties=""Excel 12.0 Xml;HDR=Yes;IMEX=0"";"
    objRecordset.Open "Select * FROM [ShptDb$]", objConnection
    Sheet2.Range("A2").CopyFromRecordset objRecordset
    objRecordset.Close
    objConnection.Close
End If
Exit Sub
FileMissing:
MsgBox "Please browse for the database file"
BrowseForFile




End Sub

I want to merge D:\DepositData.xlsx and D:\DepositData.xlsx1 so after I syn it, I can see all data from both database. Thanks in advance all masters.
 
Upvote 0
Hi

I would use Power Quer aka Get and transform.
Can be done easily with the UI.

PS: D:\DepositData.xlsx1 ist not an Excel file.

 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,633
Members
452,661
Latest member
Nonhle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top