Need to convert hundreds of .dbf to .csv

djl0525

Well-known Member
Joined
Dec 11, 2004
Messages
1,240
I have hundreds of .dbf files that I am manually converting to .csv using Excel. Unfortunately, my .dbf collection is growing faster than I can convert them. Is there a way to convert all the .dbf files in the current folder to .csv? All the .dbf files are in the same folder. The path to them would be the same as the macro file.

Any assistance will be greatly appreciated.

-- DJ
 
Great!

Last question, from my questions above, do you know how to count the *.dbf file in the path?

Sometimes there will be 200 files to convert. I wish there was a way to display something on the screen like "Please wait..." so Excel doesn't look idle.

Thanks for your help! -- DJ
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
This is how I would do it:

Add the RED code below to your macro. This will update you with the current status "Converting 7 of 215" etc. in the status bar (Bottom left corner where it says "Ready"). Just make sure it positioned in the same location in your code as it is below.

Code:
Sub ConvertDBF_to_CSV()
Dim strDocPath As String
Dim strCurrentFile As String
Dim Fname As String
[COLOR="Red"]Dim sFiles[/COLOR]
[COLOR="red"]Dim x As Integer, y As Integer[/COLOR]

'* * * Edit the path to your .dbf files in the strDocPath line below!!! * * *

Application.ScreenUpdating = False


[COLOR="red"]x = 0
y = 0
sFiles = Dir(ThisWorkbook.path & "\*.dbf")

'count the files
Do Until sFiles = ""
    x = x + 1
    sFiles = Dir
Loop[/COLOR]

strDocPath = "F:\user\Files\"
'strCurrentFile = Dir(strDocPath & "*.*")
strCurrentFile = Dir(strDocPath & "*.dbf")

Do While strCurrentFile <> ""
[COLOR="red"]y = y + 1[/COLOR]
[COLOR="red"]'display current status on status bar
Application.StatusBar = "Converting " & y & " of " & x[/COLOR]
Workbooks.Open Filename:=strDocPath & strCurrentFile
Fname = Left$(strCurrentFile, Len(strCurrentFile) - 4) & ".csv"
ActiveWorkbook.SaveAs Filename:=strDocPath & Fname, FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close (False)
strCurrentFile = Dir
Loop
[COLOR="red"]Application.StatusBar = False 'release the status bar back to excel[/COLOR]
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Folks,
how can i reverse this code to convert from .csv to .dbf?? or is there a better way to do this. I have excel 2007
 
Upvote 0
Gerry

That worked like a dream - I was actually converting .dbf to .xls - but it worked very well!

Thanks
Mike
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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