Save Excel as CSV w/o Prompt

Joe Hussain

New Member
Joined
Mar 23, 2018
Messages
1
I am attempting to create a VBA macro which will save numerous excel files as CSV files without the text qualifiers before and after the text string. The below code will accomplish this, however, I can't get this to work without excel displaying the Save As prompt. How can I adjust the below code to have the CSV files saved without being prompted?? Your help is greatly appreciated.

Dim xRg As Range
Dim xRow As Range
Dim xCell As Range
Dim xStr As String
Dim xTxt As String
Dim xName As Variant
On Error Resume Next
If ActiveWindow.RangeSelection.Count > 1 Then
xTxt = ActiveWindow.RangeSelection.AddressLocal
Else
xTxt = ActiveSheet.UsedRange.AddressLocal
End If
Set xRg = Application.Selection
If xRg Is Nothing Then Exit Sub
Application.DisplayAlerts = False
xName = Application.GetSaveAsFilename("U:\ConvPfd.csv")
Open xName For Output As #1
For Each xRow In xRg.Rows
xStr = ""
For Each xCell In xRow.Cells
xStr = xStr & xCell.Value & Chr(9)
Next
While Right(xStr, 1) = Chr(9)
xStr = Left(xStr, Len(xStr) - 1)
Wend
Print #1 , xStr
Next
Close #1
Application.DisplayAlerts = True
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
The program is doing what you told it to do. You are being prompted because you are specifically calling the GetSaveAsFilename user dialog.

Code:
xName = Application.GetSaveAsFilename("U:\ConvPfd.csv")

For example, you would not be prompted if you used
Code:
xName = "U:\ConvPfd.csv"
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,811
Members
449,339
Latest member
Cap N

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