Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Oct 2002
    Location
    Wellington, Wellington, New Zealand
    Posts
    621
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FileDialog or is there something better (2002)

    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. <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    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?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileDialog or is there something better (2002)

    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

  3. #3
    5 Star Lounger
    Join Date
    Oct 2002
    Location
    Wellington, Wellington, New Zealand
    Posts
    621
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileDialog or is there something better (2002)

    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. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •