Copy excel data to DBF file and save it as DBF File using VBA

ak577

New Member
Joined
May 15, 2019
Messages
2
Hi All,

I am new to VBA. I want to create a VBA macro to copy three worksheets of the same workbook(closed workbook) except the first row and paste into 3 different .dbf files. Is there any way to do it. I have create a rough code. Any suggestions would be helpful.

Private Sub CommandButton1_Click()


Dim StrPath1 As String
Dim StrPath2 As String
Dim StrPath3 As String
Dim StrPath4 As String
Dim Tags As Workbook
Dim sheet1 As Variant
Dim sheet2 As Variant
Dim sheet3 As Variant
Dim dbConn1 As Object
Dim dbConn2 As Object
Dim dbConn3 As Object


'Define Paths and filenames
StrPath1 = "C:\Tags.xlsx"
StrPath2 = "C:\sheet1.dbf"
StrPath3 = "C:\sheet2.dbf"
StrPath4 = "C:\sheet3.dbf"




'Create Connection with the 3 DBFs
Set dbConn1 = CreateObject("ADODB.Connection")
dbConn1.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & StrPath2 & ";Extended Properties=dBASE IV;"


Set dbConn2 = CreateObject("ADODB.Connection")
dbConn2.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & StrPath3 & ";Extended Properties=dBASE IV;"


Set dbConn3 = CreateObject("ADODB.Connection")
dbConn3.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & StrPath4 & ";Extended Properties=dBASE IV;"








'Disable screen flickering.
Application.ScreenUpdating = False

'Open files
Set Workbook1 = Workbooks.Open(StrPath1)




'Clear Previous contents
sheet1.Worksheets("variable").Range("A2:T2").End(xlDown).Clear
sheet2.Worksheets("digalm").Range("A2:U2").End(xlDown).Clear
sheet3.Worksheets("trend").Range("A2:W2").End(xlDown).Clear


Tags.Worksheets("Sheet1").Range("A2").End(xlDown).End(xlToRight).Copy sheet1.Worksheets("Sheet1").Range("A2")
Tags.Worksheets("Sheet2").Range("A2").End(xlDown).End(xlToRight).Copy sheet2.Worksheets("Sheet1").Range("A2")
Tags.Worksheets("Sheet3").Range("A2").End(xlDown).End(xlToRight).Copy sheet3.Worksheets("Sheet1").Range("A2")

End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,221,792
Messages
6,161,995
Members
451,735
Latest member
Deasejm

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