LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default unable to Find the size of the file throwing exception

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception from HRESULT: 0x800A03EC - COM Exception Unhandled Karthizen[_2_] Excel Programming 3 March 16th 09 09:54 PM
How do I find invisible objects contributing to excel file size? Francis O Excel Discussion (Misc queries) 4 October 15th 08 02:26 AM
EXCEL VBA - Find Method or Range in IE throwing error Malik Excel Programming 3 March 30th 08 05:39 PM
Unable to open excel file and when view the file size show as 1 KB Kamal Siva Excel Discussion (Misc queries) 1 March 7th 06 03:23 AM
Unable to change plot area size Shinichi Excel Programming 1 September 26th 03 02:50 AM


All times are GMT +1. The time now is 12:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"