• Question about FileDialog

    From Keith Tizzard@21:1/5 to All on Fri Sep 18 04:00:08 2020
    I have found an oddity with FileDialog when wishing to Save a file

    I have the code:

    Function fileDialogSaveExcelFile(ByRef FileName, theTitle As String, buttonLabel As String, Optional initialDir As String = "") As Long
    On Error GoTo errorCode
    Dim fDialog As fileDialog

    Set fDialog = Application.fileDialog(msoFileDialogSaveAs)
    With fDialog
    .AllowMultiSelect = False

    .Title = theTitle
    .InitialFileName = FileName
    .ButtonName = "Save"
    End With

    If fDialog.Show = -1 Then
    FileName = fDialog.SelectedItems(1)
    fileDialogSaveExcelFile = fileDialogSuccess
    Else
    fileDialogSaveExcelFile = False
    End If

    exitCode:
    Exit Function
    errorCode:
    MsgBox Err.Description, , "Error (fileDialogSaveExcelFile) " & Err.Number
    Resume exitCode
    Resume
    End Function


    If the user chooses a file name that already exists the .Show gives a warning:

    <file name> already exists.
    Do you want to replace it?

    If the user responds ‘Yes’ I would have expected the command to delete the existing file but it does not. .Show returns -1 if the file does not already exist or if the user wishes to replace it. It does not distinguish between the two.

    I have experienced a problem when creating an Excel spreadsheet. If the file already exists the new spreadsheet output can be muddled.

    Is there a way with FileDialog that the file to be replaced will be deleted?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Ulrich_M=c3=b6ller?=@21:1/5 to All on Sat Sep 19 13:34:33 2020
    Hi,

    Am 18.09.2020 um 13:00 schrieb Keith Tizzard:
    <file name> already exists.
    Do you want to replace it?

    If the user responds ‘Yes’ I would have expected the command to delete the existing file but it does not. .Show returns -1 if the file does not already exist or if the user wishes to replace it. It does not distinguish between the two.

    The return value -1 indicates that the file should be saved forcibly,
    even if an existing file should be overwritten. So the overwrite mode
    must always be set when creating a file.
    Keep in mind that the save file dialogs doesn’t actually save anything.
    It only returns the full path the user has selected to save the file.

    Ulrich

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)