Home > Software engineering >  The export file already exists, new operation results continue to add to the already existing file,
The export file already exists, new operation results continue to add to the already existing file,

Time:05-11

 
Private Sub CommandButton2_Click ()
Dim myFso
Dim myTxt
Dim BRR (), Arr, Tim, dah, I, ZDH, dh
Dh=Range (" c400000 "). The End (xlUp). Row
If dh & lt; 3 Then MsgBox "run-time error:" & amp; CRH (13) & amp; "No data in the table!" : End
Tim=Timer
ZDH=Range (" c400000 "). The End (xlUp). Row
The Set myFso=CreateObject (" Scripting. FileSystemObject ")
The Set myTxt=myFso. CreateTextFile (Filename:=ThisWorkbook Path & amp; "\ operation result. TXT", OverWrite:=True)
With myTxt
Dah=Range (" c400000 "). The End (xlUp). Row
Arr=Range (b1: "g" & amp; Dah)
ReDim BRR (1 To dah)
For I=3 To UBound (Arr)
BRR (I)=Arr (I, 1) & amp; ", "& amp; Arr (I, 2) & amp; ", "& amp; Arr (I, 3) & amp; ", "& amp; Arr (I, 4) & amp; ", "& amp; Arr (I, 5)
Next
For I=1 To dah
. WriteBlankLines 1
The.write BRR (I)
Next
. Close
End With
(q1)="timing" & amp; Format (Timer - Tim, "0.00") & amp; "Seconds"
MsgBox "at the end of operation & amp;" CRH (13) & amp; "" operation results" save E: \ test!"
The Set myTxt=Nothing
The Set myFso=Nothing
End Sub

Question:
1/no change For I=3 this code, because before the EXCEL table 2 rows with data, how to make export line TXT without 3 Spaces? The novice To learn ING
reference
For I=3 To UBound (Arr)
BRR (I)=Arr (I, 1) & amp; ", "& amp; Arr (I, 2) & amp; ", "& amp; Arr (I, 3) & amp; ", "& amp; Arr (I, 4) & amp; ", "& amp; Arr (I, 5)

2/export path set to E: \ test \ operation result. TXT, if the export file operation result. TXT exist, the exported data will continue to add to the operation result. TXT, how to modify the code, if you can't do that adding data, then the second export file, do not have to cover the original export file, establish a new serial number to 1. TXT, under an export file is 2. TXT.,,,,,,,, name of the file is 1, 2, 3, 4,,, file called natural number increasing, how to modify the code? Beginners learn ING

CodePudding user response:

On the export function, can export order TXT file,
Each derived a new TXT, file name automatically increase, TXT before 3 rows cannot be blank,
How do I modify the code?
  •  Tags:  
  • VBA
  • Related