Share via

Issue to write

Scott Huang 3,511 Reputation points
2021-03-23T08:01:18.28+00:00

Hi,
It does not write to text file per codes below. What is the reason? There is proper values in the Excel file.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Message0 As String
Message0 = ""
...
Write_to_Text_file Message0
End Sub

Sub Write_to_Text_file(Para_Dummy As String)
Dim File0 As String, RowID As Integer
File0 = Replace(Replace(ActiveWorkbook.Path & "..\Index\RangeStatus.txt", "/", "\"), "http:", "")
RowID = 1

Open File0 For Output As #1

Do While True
    RowID = RowID + 1
    If Trim(Worksheets("Main").Cells(RowID, 1).Value) = "" Then
        Exit Do
    End If
    Write #1, Trim(Worksheets("Main").Cells(RowID, 1).Value) & "," & Trim(Worksheets("Main").Cells(RowID, 2).Value) & "," & Trim(Worksheets("Main").Cells(RowID, 3).Value) & "," & Trim(Worksheets("Main").Cells(RowID, 4).Value) & "," & Trim(Worksheets("Main").Cells(RowID, 5).Value) & "," & Trim(Worksheets("Main").Cells(RowID, 6).Value) & "," & Trim(Worksheets("Main").Cells(RowID, 7).Value) & "," & Trim(Worksheets("Main").Cells(RowID, 8).Value) & "," & Trim(Worksheets("Main").Cells(RowID, 9).Value) & "," & Trim(Worksheets("Main").Cells(RowID, 10).Value)

Loop
Close #1

End Sub

Developer technologies | Visual Basic for Applications

1 answer

Sort by: Most helpful
  1. Scott Huang 3,511 Reputation points
    2021-03-23T12:56:49.6+00:00

    Hi,
    The path is correct and my loop is having way to exit properly. What is the issue?

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.