0

I'm creating an output file using FileSystemObject in Excel VBA, and I want to enable the user to choose the location where to save his output using a FileDialog box.

Here is a s snippet of my code,

Dim objFSO As FileSystemObject
Dim tsStream As TextStream
Dim strFilePath as String
Dim FD as FileDialog

Set FD = Application.FileDialog(msoFileDialogSaveAs)

With FD
    .AllowMultiSelect = False
    If .Show = -1 Then
        For Each i in .SelectedItems
            strFilePath = i
        Next i
    Else

    End If
End With
Set FD = Nothing

Set objFSO = New FileSystemObject
Set tsStream = objFSO.CreateTextFile(strFilePath &".txt", True)

The problem is the code's "Save as type:" is Excel file types.

Can anybody help me?

1

1 Answer 1

2

You can't set filters to msoFileDialogSaveAs, instead of that, to browse to a filepath, use msoFileDialogFilePicker. Now you can set filters.

Set FD = Application.FileDialog(msoFileDialogFilePicker)
FD.Filters.Clear
FD.Filters.Add "Text file", "*.txt"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.