Can anyone help by telling me what is wrong with my code. I am trying to automate saving an excel file once data has been input. The problem is I still get a command asking if I wish to save changes to the file that already exists even although i've just saved it as this filename!
VB Code:
  1. strPath = "C:\Test\"
  2. strFile = frmStartScreen.Text1.Text & ".xls"
  3. strFileName = strPath & strFile
  4.  
  5. On Error Resume Next
  6. Set objExcel = GetObject(, "Excel.Application")
  7. On Error GoTo ErrRoutine
  8. If objExcel Is Nothing Then
  9. Set objExcel = New Excel.Application
  10. End If
  11.  
  12. If Text1.Text = "1" Then
  13. With objExcel
  14. .Workbooks.Open "C:\Test\Test.xls"
  15. .Cells(1, 1) = Text3.Text
  16. .Cells(2, 1) = Text2.Text
  17. .Cells(3, 1) = Text4.Text
  18. .Cells(4, 1) = Text5.Text
  19. .Cells(5, 1) = Text6.Text
  20. .Cells(6, 1) = Text7.Text
  21. .Cells(7, 1) = Text8.Text
  22. .Cells(8, 1) = Text9.Text
  23. .ActiveWorkbook.SaveAs strFileName
  24. .ActiveWorkbook.Close savechanges:=True
  25. End With
  26. End If

I receive the message:

A file named 'C:\Test\Test.xls' already exists in this location. Do you want to replace it?

with the options to say Yes, No, Cancel

Can anyone tell me why it is asking me to save again? Have I forgotten some code or can anyone suggest a fix?



Edit: Added [vbcode][/vbcode] tags for clairty. - Hack