Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Check before overwriting file?
I am using the following to select a file name and then open file for
writing. It writes to the filename even if it is already used. Is there a way to have it check before overwriting file? Examples? ________________________________ SaveFileName = Application.GetSaveAsFilename("C:\My Documents \temp.hex", _ "Hex File (*.hex), *.hex", , "Save File As:") Open SaveFileName For Output As #1 ________________________________ |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Check before overwriting file?
Use something like
If Dir(SaveFileName) < vbNullString Then ' file exists Else ' file does not exist End If Cordially, Chip Pearson Microsoft MVP Excel Product Group Pearson Software Consulting, LLC www.cpearson.com (email on web site) On Mon, 1 Dec 2008 12:29:11 -0800 (PST), Fan924 wrote: I am using the following to select a file name and then open file for writing. It writes to the filename even if it is already used. Is there a way to have it check before overwriting file? Examples? ________________________________ SaveFileName = Application.GetSaveAsFilename("C:\My Documents \temp.hex", _ "Hex File (*.hex), *.hex", , "Save File As:") Open SaveFileName For Output As #1 ________________________________ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Check before overwriting file?
Thanks Chip. I did a search using your example and found this. It
increments the file name until it finds a unique one. It was missing an ELSE so it didn't work at first. dim filename as string dim try as long try=1 another: filename = "c:\test_" & try & ".txt" if dir(filename)<vbnullstring then 'the fiel exists! try another try=try+1 goto another msgbox("unused filename is " & filename) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to prevent overwriting of file ? | Excel Programming | |||
Rename and save without overwriting the exisiting file | Excel Programming | |||
Prevent user from overwriting file | Excel Programming | |||
overwriting a file | Excel Programming | |||
Overwriting a file automatically using saveas in a macro | Excel Programming |