Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
GetSaveAsFilename alwyas overwrites existing file
I am exporting a text file from within my macro, but it ALWAYS overwrites an
existing file without asking me if I want to replace it? Anybody know what I did wrong? FName = Application.GetSaveAsFilename("Rename_me.gft", filefilter:="GIFT files _ (*.gft), *.gft,Text files, *.txt,All Files, *.*", _ Title:="Please pick a file name for your GIFT file") If FName = False Then myMessage = "You didn't select a file." & Chr(10) & Chr(10) & "Export has been ABORTED!" GoTo MyError: End If THanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
GetSaveAsFilename alwyas overwrites existing file
GetSaveAsFilename only askes the user for a filename: it's up to you to
check if it exists and if so then ask the user what they want to do. You don't show the code which does the save: post that and I'm sure you'll get a suggestion on how to handle it. Tim "jeff" wrote in message ... I am exporting a text file from within my macro, but it ALWAYS overwrites an existing file without asking me if I want to replace it? Anybody know what I did wrong? FName = Application.GetSaveAsFilename("Rename_me.gft", filefilter:="GIFT files _ (*.gft), *.gft,Text files, *.txt,All Files, *.*", _ Title:="Please pick a file name for your GIFT file") If FName = False Then myMessage = "You didn't select a file." & Chr(10) & Chr(10) & "Export has been ABORTED!" GoTo MyError: End If THanks |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
GetSaveAsFilename alwyas overwrites existing file
Oops... forgot the save part of the macro!!!
OKay, thanks Tim... so I guess my question has now changed to "How do I check to see if the file already exists?" Here's the whole chunk of code I already have. There are no problems with it all, as far as the actual export goes, it's just that it overwrites the existing file if it already exists. '---Pick a filename and location to save--- FName = Application.GetSaveAsFilename("Rename_me.gft", _ filefilter:="GIFT files (*.gft), *.gft,Text files, *.txt,All Files, *.*", _ Title:="Please pick a file name for your GIFT file") If FName = False Then myMessage = "You didn't select a file." & Chr(10) & _ Chr(10) & "Export has been ABORTED!" GoTo MyError: End If '***Need code HERE to check if the file (FName) already exists!!!!*** '---Export To Text File--- Application.ScreenUpdating = False On Error GoTo EndMacro: FNum = FreeFile Open FName For Output Access Write As #FNum For q = 0 To 100 If qGIFT(q) < "" Then Print #FNum, qGIFT(q) Next q EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum "Tim Williams" wrote: GetSaveAsFilename only askes the user for a filename: it's up to you to check if it exists and if so then ask the user what they want to do. You don't show the code which does the save: post that and I'm sure you'll get a suggestion on how to handle it. Tim |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
GetSaveAsFilename alwyas overwrites existing file
'---Pick a filename and location to save---
FName = Application.GetSaveAsFilename("Rename_me.gft", _ filefilter:="GIFT files (*.gft), *.gft,Text files, *.txt,All Files, *.*", _ Title:="Please pick a file name for your GIFT file") If FName = False Then myMessage = "You didn't select a file." & Chr(10) & _ Chr(10) & "Export has been ABORTED!" GoTo MyError: End If if dir(fName) < "" then ans = Msgbox("File exists, overwrite?", vbYesNo) if ans = vbNo then exit sub end if Application.ScreenUpdating = False On Error GoTo EndMacro: FNum = FreeFile Open FName For Output Access Write As #FNum For q = 0 To 100 If qGIFT(q) < "" Then Print #FNum, qGIFT(q) Next q EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum -- Regards, Tom Ogilvy "jeff" wrote in message ... Oops... forgot the save part of the macro!!! OKay, thanks Tim... so I guess my question has now changed to "How do I check to see if the file already exists?" Here's the whole chunk of code I already have. There are no problems with it all, as far as the actual export goes, it's just that it overwrites the existing file if it already exists. '---Pick a filename and location to save--- FName = Application.GetSaveAsFilename("Rename_me.gft", _ filefilter:="GIFT files (*.gft), *.gft,Text files, *.txt,All Files, *.*", _ Title:="Please pick a file name for your GIFT file") If FName = False Then myMessage = "You didn't select a file." & Chr(10) & _ Chr(10) & "Export has been ABORTED!" GoTo MyError: End If '***Need code HERE to check if the file (FName) already exists!!!!*** '---Export To Text File--- Application.ScreenUpdating = False On Error GoTo EndMacro: FNum = FreeFile Open FName For Output Access Write As #FNum For q = 0 To 100 If qGIFT(q) < "" Then Print #FNum, qGIFT(q) Next q EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum "Tim Williams" wrote: GetSaveAsFilename only askes the user for a filename: it's up to you to check if it exists and if so then ask the user what they want to do. You don't show the code which does the save: post that and I'm sure you'll get a suggestion on how to handle it. Tim |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
GetSaveAsFilename alwyas overwrites existing file
Thanks Tom!
It's a very simple solution, isn't it!!!! if dir(FileName) < "" then ans = Msgbox("File exists, overwrite?", vbYesNo) if ans = vbNo then exit sub end if I also found another example it the following post (almost the same question asked at almost the same time)!!! Subject: SaveFileName in Excel 3/10/2007 9:05 PM PST By: TedT In: microsoft.public.excel.programming Thanks again! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
User replaces existing file with blank during file open | Excel Discussion (Misc queries) | |||
Macro to combine worksheets data - overwrites existing | Excel Discussion (Misc queries) | |||
Worksheets.add in VBScript overwrites existing worksheet | Excel Worksheet Functions | |||
Importing text file, only option to edit existing file | Excel Discussion (Misc queries) | |||
File save location with Application.GetSaveAsFilename | Excel Programming |