• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Help with msoFileDialogSaveAs

chirayu

Well-Known Member
Hi All,

My Save As loads but clicking the save button does nothing
Code:
Dim MyFileType As Variant
Dim savemyfile As FileDialog

Set savemyfile = Application.FileDialog(msoFileDialogSaveAs)
MyFileType = "CSV (Comma delimited)"

For i = 1 To savemyfile.Filters.Count
    If savemyfile.Filters(i).Description = MyFileType Then
        savemyfile.AllowMultiSelect = False
        savemyfile.Title = "Choose Save Location"
        savemyfile.InitialFileName = "TEST*.csv"
        savemyfile.FilterIndex = i
        savemyfile.Show
        Exit For
    Else
        i = i + 1
    End If
Next i


Same issue with the simpler version I made
Code:
Dim savemyfile As FileDialog

With savemyfile
    .AllowMultiSelect = False
    .Title = "Choose Save Location"
    .InitialFileName = "TEST*.CSV"
    .FilterIndex = 15
    .Show
End With
 
Last edited:
Try this way:
Code:
Sub test()
Dim fName As String
fName = Application.GetSaveAsFilename(InitialFileName:="TEST*.csv", FileFilter:="CSV (Comma delimited) (*.csv), *.csv", Title:="Choose Save Location")
If fName = False Then
    'User cancelled
Else
    ActiveWorkbook.SaveAs Filename:=fName
End If
End Sub
 
Thanks Luke. But same issue. Doesn't matter how many times I click the save option on the popup. It doesn't close & doesn't save. Is it because all my macros in in my personal macro workbook? so it doesn't recognize my file
 
It should at least be closing...
The Else part of the If statement is where the actual Save occurs. Even with your earlier setup, the FileDialog only retrieves a list of strings, it doesn't do anything by itself. Can you step through the code I provide using F8, and see what's going on? That fact that the Dialog appears indicates that it shouldn't be a problem with your Personal workbook.

One final question, just because it's happened before with some posters...did you copy what I posted before exactly, or make modifications? If the latter, can you post what you have?
 
I think I know the issue. Its the "*" bit of the filename as Naming convention cant have symbols like that. Seems my code works but I'm an idiot lol for adding the "*"

Edit: my thing still wouldn't save. Just closed the popup. I had an error with yours so I changed the fName= False bit to fName = "False"
 
Last edited:
Ah, I see what you mean. Asterisk kept box from closing, and then need to compare to string "False". Did/does this work?
Code:
Sub Save_CSV()
Dim fName As String
fName = Application.GetSaveAsFilename(InitialFileName:="TEST.csv", FileFilter:="CSV (Comma delimited) (*.csv), *.csv", Title:="Choose Save Location")
If fName = "False" Then
    'User cancelled
Else
    ActiveWorkbook.SaveAs Filename:=fName
End If
End Sub
 
Back
Top