I have code that in August when I created was working fine. For some reason today, the csv file that is created is empty. I have not changed anything to the code and when I step through the code things look like they work, but the file is empty.
Here is the code that calls the procedure that creates the csv.
Here is the code that creates the csv
Any ideas? I am using Excel 2002 SP3
Thanks
Here is the code that calls the procedure that creates the csv.
Code:
Private Sub cmdCreateFile_Click()
Dim ManualLastRow As Long
Dim ManualLast As Integer
Dim i As Integer
Dim ManualFileName As String
Dim rngError As Range
Dim Ans As Integer
Dim AnsPool As Integer
Application.ScreenUpdating = False
If wsNewLoans.Range("c2").Value = "" Then
AnsPool = MsgBox("The pool number is missing, please add it to cell B9.", vbOKOnly, "Verify Pool Number Provided")
Exit Sub
End If
ManualLastRow = Cells(Cells.Rows.Count, "b").End(xlUp).Row
ManualLast = ManualLastRow
ManualFileName = wsNewLoans.Range("c2").Value
'use the answer to know whether or not to continue
Ans = MsgBox("Is " & ManualFileName & " the correct pool number?", vbYesNo + vbQuestion, "Verify Pool")
If Ans = vbNo Then
Exit Sub
Else
Call RemoveLeadingZero
Call SetDateAsText
Call FormatValues
Call FindReplace
Range("a9" & ":am" & ManualLast).Select
On Error Resume Next
Set rngError = Range("a9" & ":am" & ManualLast).SpecialCells(xlCellTypeFormulas, 16).Value
On Error GoTo 0
If Not rngError Is Nothing Then
MsgBox "There was an error in the file."
Else
' MsgBox "Things look good"
Columns("R:T").EntireColumn.Hidden = False
Call ExportToTextFile(ManualFileName)
Columns("R:T").EntireColumn.Hidden = True
End If
Call ClearRecords
wsNewLoans.Range("b9").Select
End If
End Sub
Here is the code that creates the csv
Code:
Public Sub ExportToTextFile(ManualFName As String)
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
Dim FName As Variant
Dim Sep As String
Dim TextFileName As String
'Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile
With Selection
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
FName = "P:\Input\SFP\LoanData\" & ManualFName & "_loans.csv"
Sep = ","
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 = ""
Else
CellValue = Cells(RowNdx, ColNdx).Text
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
Any ideas? I am using Excel 2002 SP3
Thanks