> It would help to know what the errors you're getting are...
>
> Some things that jump out at me are:
>
> - you don't need the Set keyword when defining Path, xlsfname and xltfname
> - you need a slash at the end of the definition of Path.
> - you need quotes around the values for xlsfname and xltfname
> - check first whether Path & xlsfname exists before issuing the Kill
> command:
>
> Path = "C:\Documents and Settings\PR\My Documents\Downloads\AWSA
> Database\"
> Set xlsfname = "aga_export.xls"
> Set xltfname = "aga_export.xlt"
>
> If Len(Dir(Path & xlsfname)) > 0 Then
> Kill Path & xlsfname
> End If
>
>
> --
> Doug Steele, Microsoft Access MVP
>
http://I.Am/DougSteele> (no private e-mails, please)
>
>
> "PR" <PR[ at ]discussions.microsoft.com> wrote in message
> news:FDFE2C5C-3D92-4E4C-9349-F23E991D488B[ at ]microsoft.com...
> >I am trying to delete, open, save and transfer data to excel I am using the
> > following code but I am getting some errors... could someone suggest what
> > is
> > wrong with the code...
> >
> > Many Regards - PR
> > My Code:
> > Function export_aga()
> > On Error GoTo export_aga_Err
> >
> > Dim db As Database
> > Dim objApp As Excel.Application
> > Dim ObjBook As Excel.Workbook
> > Dim objSheet As Excel.Worksheet
> > Dim Path As String
> > Dim xlsfname As String
> > Dim xltfname As String
> >
> > Set db = CurrentDb()
> > Set objApp = New Excel.Application
> > Set Path = "C:\Documents and Settings\PR\My Documents\Downloads\AWSA
> > Database"
> > Set xlsfname = aga_export.xls
> > Set xltfname = aga_export.xlt
> >
> > 'delete the spreadsheet
> > Kill Path & xlsfname
> >
> > ' create a workbook from the template
> > Set ObjBook = objApp.Workbook.Open(Path & xltfname)
> >
> > ' save a template as a workbook
> > objXLBook.SaveAs (Path & xlsfname)
> > objXLBook.Close
> >
> > ' transfer data to new wookbook
> > DoCmd.SetWarnings False
> > DoCmd.TransferSpreadsheet acExport, 8, "qry_AGA_Corps", Path &
> > xlsfname, ""
> > DoCmd.SetWarnings True
> >
> > Set db = Nothing
> > Set objApp = Nothing
> > Set ObjBook = Nothing
> > Set objSheet = Nothing
> >
> > export_aga_Exit:
> > Exit Function
> >
> > export_aga_Err:
> > MsgBox Error$
> > Resume export_aga_Exit
> >
> > End Function
>
>
>