Hi Guys!!!
In my previous post I used Write function to write the data into notepad file . Write function will write data with double quotes. To avoid the double quotes instead of WRITE function use PRINT,
Sub Writenotepadwithoutquotes()
'Declaring variables
Dim TxtFile As String, rng As Range, TextValue As Variant, i As Integer, j As Integer, TextFile As Integer
'Provide the notepad file name
TxtFile = ActiveWorkbook.Path & "\result.txt"
'Determine the next file number available for use by the FileOpen function
TextFile = FreeFile
'Selecting the range . This can be also parameterized
Range("A1:E6").Select
Set rng = Selection
Open TxtFile For Output As #TextFile
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
TextValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
'Print will write data without double quotes
Print #TextFile, TextValue
Else
Print #TextFile, TextValue,
End If
Next j
Next i
Close #TextFile
End Sub
In my previous post I used Write function to write the data into notepad file . Write function will write data with double quotes. To avoid the double quotes instead of WRITE function use PRINT,
Sub Writenotepadwithoutquotes()
'Declaring variables
Dim TxtFile As String, rng As Range, TextValue As Variant, i As Integer, j As Integer, TextFile As Integer
'Provide the notepad file name
TxtFile = ActiveWorkbook.Path & "\result.txt"
'Determine the next file number available for use by the FileOpen function
TextFile = FreeFile
'Selecting the range . This can be also parameterized
Range("A1:E6").Select
Set rng = Selection
Open TxtFile For Output As #TextFile
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
TextValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
'Print will write data without double quotes
Print #TextFile, TextValue
Else
Print #TextFile, TextValue,
End If
Next j
Next i
Close #TextFile
End Sub
No comments:
Post a Comment