Overwriting an Excel file

EagleEyeVB

New member
Joined
Aug 28, 2005
Messages
4
Programming Experience
Beginner
Hi, I need to overwrite an Excel spreadsheet file, but can't seem to figure it out. I'm not using a file dialog window, just saving directly to the same location. Here's my code:

'Create a new workbook in Excel.
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)

oSheet.Range("A1").Value = "Test"

'Save the workbook and quit Excel.
oBook.SaveAs("Test.xls")
oSheet = Nothing
oBook = Nothing
oExcel.Quit()


It prompts me,

A file named "Test.xls" already exits in this location. Do you want to replace it?

at the oBook.SaveAs("Test.xls"). How do I turn that off, so it doesn't prompt the message?

Thanks for your help.
 
it seems like there should be an overwrite boolean argurment on the saveas method like:

oBook.SaveAs("Test.xls", True)

but i dont have that object here (as of yet, i'll get to it next weekend)
 
Thanks guys, but I couldn't get this to work. I just did a work around by deleting all the files in that directory before saving to it. This works fine for my purpose.

Thanks again.
 
Back
Top