Exporting TextFile with SaveAsWindow Prompt


New Member
Sep 30, 2014

I am a VBA "dummy" so please bear with me.

I am currently working on a "Lookup" program. There is an Export button on my user form, but the text file generated saves automatically in a user's directory (e.g., My Documents).

Here is the code:

Private Sub Export_Click()
Dim OutCount As Integer
'exports the list to a text file (max 200 rows)
If ItemCount > 0 Then
Open "PRODLIST.txt" For Output As #1
For OutCount = 1 To ItemCount
If ItemCount < 201 Then
Print #1, ListArray(OutCount)
End If
Close #1
MsgBox ("List output to file PRODLIST.txt saved to your default directory")
If ItemCount > 200 Then
MsgBox ("Warning - list incomplete - only contains first 200 entries")
End If
End If
End Sub

Now my question: How can I get the SaveAs prompt window instead of the text file saving automatically to My Documents?

I looked around and got:

FILENAME = Application.Dialogs(xlDialogSaveAs).Show


I can't figure out how to modify my existing code.

Any insight would be greatly appreciated!

Damon Ostrander

MrExcel MVP
Feb 17, 2002
Hi SirCurious,

The easy way to do this is to use the workbook's GetSaveAsFilename method to get the path and filename where you want the file saved. This brings up the SaveAs dialog, and yields the path & filename. Then use the Open statement to write the file directly to the path & filename.


Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...