question

Jackson1990-7147 avatar image
0 Votes"
Jackson1990-7147 asked emizhang-msft edited

Issue to write

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


office-vba-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Did you check if File0 is a valid path? Show some details. Also check that the 'Write #1' line was actually achieved by your loop.


0 Votes 0 ·

1 Answer

Jackson1990-7147 avatar image
0 Votes"
Jackson1990-7147 answered Viorel-1 commented

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


If possible, show the exact value of File0 here, or fix it if you already found the problem.

1 Vote 1 ·