Save as DBF

B

bijan

Hi
I'am using excel 2003, need a sample code for save as a non-active
sheet("test") to dBASE IV in C:\test\test.dbf and dont save as my workbook.
Thanks in advance
 
J

Joel

'create new workbook with only one sheet
'copy without using before or after put sheet in new workbook
Sheets("test").Copy
Set Newbk = ActiveWorkbook
Newbk.SaveAs _
Filename:="C:\test\test.dbf", _
FileFormat:=xlDBF4
Newbk.Close savechanges:=True
 
B

bijan

Hi,Joel
Thanks for code,How can change this code to ask me by a message box to set a
filename instead of test.dbf
Thanks
Bijan
 
J

Joel

fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="DBF Files (*.dbf), *.dbf")
If fileSaveName <> False Then
MsgBox("Cannot open file - Exiting macro")
exit sub
End If


Sheets("test").Copy
Set Newbk = ActiveWorkbook
Newbk.SaveAs _
Filename:=fileSaveName, _
FileFormat:=xlDBF4
Newbk.Close savechanges:=True
 
B

bijan

Thanks Jole
It works grate but I had to remove this part:
If fileSaveName <> False Then
MsgBox("Cannot open file - Exiting macro")
exit sub
End If
beacuse, it just returns the text of msgbox
Bijan
 
J

Jacob Skaria

Joel meant = False as below ... to exit the macro if no file is selected..

If fileSaveName = False Then
MsgBox ("Cannot open file - Exiting macro")
Exit Sub
End If

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top