Saving an Excel worksheet

  • Thread starter Marius from Rome
  • Start date
M

Marius from Rome

My Access application opens an existing Excel worksheet and inserts data in
it.
My application should give my worksheet a new file name (i.e.
newworksheet.xls), save and close it.
I attempted using the .saveas and .close methods, but if a file with the
same name altrady exists I don't get any error while the user is prompted to
save changes in the original file.
Can anybody please suggest the best and simplest way to check if a file with
the new name already exists and/or to overwrite it?
Regards
marius
 
J

John Nurick

Hi Marius,

You can use the Dir() function, something like this:

Dim strNewName as String

strNewName = "newworksheet.xls"
With MyWorksheet
If Len(Dir(.Path & "\" & strNewName)) > 0 Then
'File already exists
Kill .Path & "\" & strNewname
End If
.SaveAs strNewName
.Close
End With
 

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