After a lot of work and testing (very pathetic indeed), I finally managed to select a range in worksheets, then copy/paste it in Notepad. The file shall be thereafter readen by another app. Unfortunately, the app reject the file and there is no way for me to debug why. The only message I have is an error occuring at last line.
Surprisingly, when I copy-paste to notepad by hand, it works. As far as my eyes can see, both txt files (the one writen with my sub() and the one from CP by hand) are exactly the same. I guess my eyes are wrong. I suspect there is at the end of last line or below last row maybe some white space I can not see. The only part of code I do not fully understand is, according to me, the place of the current issue.
Find below part of my code:
[code]
' RngSelect is a Variant and effectively a range of cells
' Txt is a Variant
' LastRow is a Long equal to last row number of my range
With RngSelect
For Lg1 = 1 To LastRow
Txt = Txt & vbCrLf & Join$(Application.Transpose(Application.Transpose(.Rows(Lg1).Value)),vbTab) ' copy each row
Next
End With
Open FilePath For Output As #1
Print #1, Mid$(Txt, Len(vbCrLf) + 1)
Close #1
RngSelect = Null
Txt = Null
End Sub
If it can help, my file to be imported by the other app can be in a csv format. Currently, my delimiter is Tab.
Thank you for help.
Following this post, I finally managed to erase the last blank line at the bottom of my text . The the correct line now is :
Print #1, Mid$(txt, Len(vbCrLf) + 1) ;
I then had to modify my LastRow, as it is the row number on my spreadsheet but not the last row number on my text file. I shall now find a way to append the text in the text file.