B
Bobby
When i excute this file. when the cursor reaches the position
" LResult = FileSize(Filename)" It is going to the "ErrorHandler:
ActiveSheet.Columns((GetColumnCount + 1)).ClearContents"
Please let me know what wrong iam doing in this code.
..Public Sub ExportToFile()
On Error GoTo ErrorHandler
Dim ts As TextStream
Dim Filename As String, fileContent As String, tableName As String,
delimiter As String
Dim rowCount As Long, columnCount As Long, dataColumn As Long, pageSize
As Long
Dim pageNumber As Integer
Dim tempRange As Range, tempCell As Range
Dim ws As Worksheet
Dim MyName As String
Dim xpathname As String
Dim fso As FileSystemObject
Dim LResult As Long
Dim ConstLen As Long
For Each ws In ActiveWorkbook.Worksheets
Filename = ws.Name
If Filename <> "Anvil" Then
Worksheets(Filename).Activate
'fileName = GetDefaultFileName(wkSheetName)
If Filename = "" Then Exit Sub
'fileName = Application.GetSaveAsFilename(fileName, "Data Files
(*.txt),*.txt", _
' 1, "Save Data File", "Export")
xpathname = ThisWorkbook.Path
Filename = xpathname & "\" & Filename & ".txt"
LResult = FileSize(Filename)
ConstLen = 0
If LResult = ConstLen Then
ConstLen = 1
ElseIf MsgBox("The file " & fso.GetFileName(Filename) & " already exists.
Do " & _
"you want to replace the existing file?", vbYesNo +
vbExclamation + _
vbDefaultButton2, PROJECT_NAME) = vbNo Then
Exit Sub
End If
Set fso = New FileSystemObject
fso.CreateTextFile Filename, overwrite:=True
Exit Sub
ErrorHandler:
ActiveSheet.Columns((GetColumnCount + 1)).ClearContents
MsgBox MSG2002, vbOKOnly + vbCritical, PROJECT_NAME
End Sub
Public Function FileSize(Filename As String) As Long
Dim objX As Object
Set objX = CreateObject("Scripting.FileSystemObject")
FileSize = objX.GetFile(Filename).Size
Set objX = Nothing
End Function
" LResult = FileSize(Filename)" It is going to the "ErrorHandler:
ActiveSheet.Columns((GetColumnCount + 1)).ClearContents"
Please let me know what wrong iam doing in this code.
..Public Sub ExportToFile()
On Error GoTo ErrorHandler
Dim ts As TextStream
Dim Filename As String, fileContent As String, tableName As String,
delimiter As String
Dim rowCount As Long, columnCount As Long, dataColumn As Long, pageSize
As Long
Dim pageNumber As Integer
Dim tempRange As Range, tempCell As Range
Dim ws As Worksheet
Dim MyName As String
Dim xpathname As String
Dim fso As FileSystemObject
Dim LResult As Long
Dim ConstLen As Long
For Each ws In ActiveWorkbook.Worksheets
Filename = ws.Name
If Filename <> "Anvil" Then
Worksheets(Filename).Activate
'fileName = GetDefaultFileName(wkSheetName)
If Filename = "" Then Exit Sub
'fileName = Application.GetSaveAsFilename(fileName, "Data Files
(*.txt),*.txt", _
' 1, "Save Data File", "Export")
xpathname = ThisWorkbook.Path
Filename = xpathname & "\" & Filename & ".txt"
LResult = FileSize(Filename)
ConstLen = 0
If LResult = ConstLen Then
ConstLen = 1
ElseIf MsgBox("The file " & fso.GetFileName(Filename) & " already exists.
Do " & _
"you want to replace the existing file?", vbYesNo +
vbExclamation + _
vbDefaultButton2, PROJECT_NAME) = vbNo Then
Exit Sub
End If
Set fso = New FileSystemObject
fso.CreateTextFile Filename, overwrite:=True
Exit Sub
ErrorHandler:
ActiveSheet.Columns((GetColumnCount + 1)).ClearContents
MsgBox MSG2002, vbOKOnly + vbCritical, PROJECT_NAME
End Sub
Public Function FileSize(Filename As String) As Long
Dim objX As Object
Set objX = CreateObject("Scripting.FileSystemObject")
FileSize = objX.GetFile(Filename).Size
Set objX = Nothing
End Function