• FileDialog or is there something better (2002)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » FileDialog or is there something better (2002)

    Author
    Topic
    #407479

    I’m wishing to create an internally generated .csv file – that’s the easy part.

    My problem relates to asking the user where to save it. confused
    I’d written

    With Application.FileDialog(msoFileDialogFilePicker)
    .InitialFileName = Replace(ActiveWorkbook.FullName, “.xls”, “.csv”)
    .Filters.Add “Comma Separated FIle”, “*.csv”, 1
    .Show
    Open .SelectedItems(1) For Output As #1
    End With

    as my piece of code – but, the filepicker does not let me create a new filename on its selection.

    How do I get the ability to have user pick the new output file?

    Viewing 1 reply thread
    Author
    Replies
    • #852625

      Excel has GetSaveAsFileName:

      Dim varFile As Variant
      varFile = Application.GetSaveAsFilename(“*.csv”, “CSV files (*.csv),*.csv”)
      If varFile = False Then
      Exit Sub
      Else

      End If

      or use FileDialog with msoFileDialogSaveAs:

      Dim strFile As String
      With Application.FileDialog(msoFileDialogSaveAs)
      .FilterIndex = 10
      If .Show = True Then
      strFile = .SelectedItems(1)
      End If
      End With

      • #852627

        Hans
        Thanks for the speedy reply – just what I was looking for.

        I’ll opt for the Excel version (I’d already tried FIleDialogSaveAs and help didn’t seem to admit to having either the .Filter, or the .SelectedItems properties – but I admit I hadn’t thought to try them. grin

      • #852628

        Hans
        Thanks for the speedy reply – just what I was looking for.

        I’ll opt for the Excel version (I’d already tried FIleDialogSaveAs and help didn’t seem to admit to having either the .Filter, or the .SelectedItems properties – but I admit I hadn’t thought to try them. grin

    • #852626

      Excel has GetSaveAsFileName:

      Dim varFile As Variant
      varFile = Application.GetSaveAsFilename(“*.csv”, “CSV files (*.csv),*.csv”)
      If varFile = False Then
      Exit Sub
      Else

      End If

      or use FileDialog with msoFileDialogSaveAs:

      Dim strFile As String
      With Application.FileDialog(msoFileDialogSaveAs)
      .FilterIndex = 10
      If .Show = True Then
      strFile = .SelectedItems(1)
      End If
      End With

    Viewing 1 reply thread
    Reply To: Reply #852628 in FileDialog or is there something better (2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel