Tyke Posted September 23, 2010 Share Posted September 23, 2010 I have the situation where the insertion points of a number of circles are written to an ASCII file for use in another programm. A filename is automatically sugested and if the user accepts it the file is saved, overwriting any existing file with the same name, if it exists and without displaying an alert message, eg "Do want to overwrite the existing file?". Hers's the code for the function that I'm currently using Public Function ShowSave(Filter As String, _ InitialDir As String, _ DialogTitle As String) As String Dim SFName As SAVEFILENAME ShowSave = "" ' suggest a file name SFName.lpstrFile = strAsciiFileName 'Set the structure size SFName.lStructSize = Len(SFName) 'Set the owner window SFName.hwndOwner = 0 'Set the filter SFName.lpstrFilter = Filter 'Set the maximum number of chars SFName.nMaxFile = 255 'Create a buffer SFName.lpstrFileTitle = strAsciiFileName 'Set the maximum number of chars SFName.nMaxFileTitle = 255 'Set the initial directory SFName.lpstrInitialDir = InitialDir 'Set the dialog title SFName.lpstrTitle = DialogTitle 'no extra flags SFName.flags = 0 'Show the 'SaveAs File’ dialog If GetSaveFileName(SFName) Then ShowSave = Trim(SFName.lpstrFile) Else ShowSave = "QUIT" End If End Function Is it possible to easily implement such an alert? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 23, 2010 Share Posted September 23, 2010 Yes. I do not do much VBA development (I primarily use the Visual LISP ActiveX COM API), but conceptually speaking... You could use a nested if statement, such that once the user accepts a filename, *IF* the filename already exists, prompt for overwrite, else create/save new file. For example (forgive my poor VBA syntax): If [color=red]Save[/color][color=red]FileName[/color] Then If [color=red]Save[color=red]FileName_[/color]Exists[/color]=[color=blue]Yes[/color] Then If [color=red]PromptForOverwrite[/color]=[color=blue]Yes[/color] Then [color=seagreen]' Overwrite file[/color] Else [color=seagreen]' Prompt for new filename (start this process over? [/color] [color=seagreen] ' Perhaps make it a sub-routine?)[/color] End If End If Else [color=seagreen]' Create/Save new file[/color] End If The LISP function that comes to mind is findfile (not sure of the vba equivillent?). Hope this helps! Quote Link to comment Share on other sites More sharing options...
Tyke Posted September 23, 2010 Author Share Posted September 23, 2010 I tried adapting the code, but without success. Thanks for the advice. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.