Exporting TextFile with SaveAsWindow Prompt

SirCurious_VBAExcel

New Member
Joined
Sep 30, 2014
Messages
17
Hello,

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
Next
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!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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.

Damon
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,442
Members
448,898
Latest member
drewmorgan128

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top