PDA

View Full Version : Solved: No warning when overwriting file



abhiker
01-13-2009, 02:02 PM
I am writing out an XML file from my Excel workbook and i do not get a warning if i am about to overwrite an existing file. I am using the following code to write the file. Any suggestions or changes to get the overwrite warning would be appreciated.


Dim objFSO As FileSystemObject

Set objDoc = New DOMDocument

fn = Application.GetSaveAsFilename _
(strQ, "XML Files (*.xml),*.xml", , "Save XML Query")

If fn <> False Then
Call objDoc.Save(fn)
MsgBox ("File saved to: " & fn)
Else
MsgBox ("WARNING: File Not saved!!")
Exit Sub
End If

chungtinhlak
01-13-2009, 06:08 PM
i tried this today and it works.

ChDir "Your path to save goes here"
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="your file name goes here (including extension)"
Application.DisplayAlerts = True

Kenneth Hobs
01-13-2009, 09:33 PM
Not sure why that is an issue. If they select the file, then it must exist. Why would they need another warning?

Use DIR to determine if the fn exists or use fso's Exist property.

abhiker
01-14-2009, 05:59 AM
Solved. Thank you.