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