S
Sharbat
Hello
I am using the following procedure, in order to copy the text from one
of the column of an Excel sheet into a text file.
But I like to say that this procedure can’t copy the entire text
into a text file.
Currently it copies the text before the following line that is the
special character (# ) which is the part of TEXT Data:
##################################################
#
The text data of the column of an excel sheet contains special
character like #.
This is the nature of this text data.
I think the above special character line halt the further process. How
should we solve this issue?
Below we find some of the text data which is available in the column
of an excel sheet.
Suggestions will be appreciated.
Thanks
Sharbat
Some part of Text data from the column of an excel sheet:
PARSE #4:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=
961103
PARSING IN CURSOR #3 len=809 dep=0 uid=5 oct=47 lid=5 tim=961103
hv=2641313648 ad='3be0abc'
##################################################
#
PARSE #4:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=
961103
PARSE #4:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=
961103
VBA CODE Which I got from the NET:
Exporting To Text Files
Public Sub ExportToTextFile(FName As String, _
Sep As String,
SelectionOnly As Boolean)
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim CellValue As String
Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile
If SelectionOnly = True Then
With Selection
StartRow = .Cells(1).row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).row
EndCol = .Cells(.Cells.Count).Column
End With
Else
With ActiveSheet.UsedRange
StartRow = .Cells(1).row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).row
EndCol = .Cells(.Cells.Count).Column
End With
End If
Open FName For Output Access Write As #FNum
For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = Chr(34) & Chr(34)
Else
CellValue = _
Application.WorksheetFunction.Text _
(Cells(RowNdx, ColNdx).Value, _
Cells(RowNdx, ColNdx).NumberFormat)
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum
End Sub
WE can call this macro from another VBA procedure as follows:
ExportToTextFile "c:\temp\test.txt", ";" , FALSE
I am using the following procedure, in order to copy the text from one
of the column of an Excel sheet into a text file.
But I like to say that this procedure can’t copy the entire text
into a text file.
Currently it copies the text before the following line that is the
special character (# ) which is the part of TEXT Data:
##################################################
#
The text data of the column of an excel sheet contains special
character like #.
This is the nature of this text data.
I think the above special character line halt the further process. How
should we solve this issue?
Below we find some of the text data which is available in the column
of an excel sheet.
Suggestions will be appreciated.
Thanks
Sharbat
Some part of Text data from the column of an excel sheet:
PARSE #4:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=
961103
PARSING IN CURSOR #3 len=809 dep=0 uid=5 oct=47 lid=5 tim=961103
hv=2641313648 ad='3be0abc'
##################################################
#
PARSE #4:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=
961103
PARSE #4:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=
961103
VBA CODE Which I got from the NET:
Exporting To Text Files
Public Sub ExportToTextFile(FName As String, _
Sep As String,
SelectionOnly As Boolean)
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim CellValue As String
Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile
If SelectionOnly = True Then
With Selection
StartRow = .Cells(1).row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).row
EndCol = .Cells(.Cells.Count).Column
End With
Else
With ActiveSheet.UsedRange
StartRow = .Cells(1).row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).row
EndCol = .Cells(.Cells.Count).Column
End With
End If
Open FName For Output Access Write As #FNum
For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = Chr(34) & Chr(34)
Else
CellValue = _
Application.WorksheetFunction.Text _
(Cells(RowNdx, ColNdx).Value, _
Cells(RowNdx, ColNdx).NumberFormat)
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum
End Sub
WE can call this macro from another VBA procedure as follows:
ExportToTextFile "c:\temp\test.txt", ";" , FALSE