the code below works ok in 2003. I made one minor change
from
DBaseName = Folder & BaseName & ".dbf"
to
DBaseName = Folder & BkName & ".dbf"
The problem above create a filename with and extension .xls.dbf instead
of .dbf
The SAVEAS has a problem when the workbooks contains more than one
sheet. The line "template:=xlWBATWorksheet" creates a workbook with one
sheet. You other changes made the code create non-related errors. The
1004 error was due to the fact workbook that you opened had more than
one sheet. That is why I copied the the filtered sheet to a new
workbook before saving as a dbf file.
Sub SaveDBF()
Folder = "c:\BobDev\"
BaseName = "Stores_" & Format(Date, "mmddyy")
BkName = Folder & BaseName & ".xls"
Set bk = Workbooks.Open(Filename:=BkName)
'create workbook to copy filtered data
'Original Source: The Code Cage Forums
http://tinyurl.com/yhtubl7
Set bk2 = Workbooks.Add(template:=xlWBATWorksheet)
With bk.Sheets(1)
'select autofilter to select Dept A
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Columns("A:A").AutoFilter
.Columns("A:A").AutoFilter Field:=1, Criteria1:="A"
'copy only filtered rows
.Rows("1:" & LastRow).SpecialCells(xlCellTypeVisible).Copy _
bk2.Sheets(1).Rows(1)
End With
'create new filename to save file
DBaseName = Folder & BaseName & ".dbf"
bk2.SaveAs Filename:=DBaseName, _
FileFormat:=xlDBF4
bk.Close savechanges:=False
bk2.Close savechanges:=False
End Sub
--
joel
------------------------------------------------------------------------
joel's Profile:
http://www.thecodecage.com/forumz/member.php?userid=229
View this thread:
http://www.thecodecage.com/forumz/showthread.php?t=153064
Microsoft Office Help
.