Sub CrText()
Dim c00 As Variant
Const textFilePath As String = "C:\Desktop\myTextFile.txt"
Dim lngCounter As Long
Dim FF As Integer
FF = VBA.FreeFile
c00 = Range("A1").CurrentRegion
Open textFilePath For Output As #FF
For lngCounter = LBound(c00, 1) To UBound(c00, 1)
Print #FF, Join(Application.Index(c00, lngCounter, 0), vbTab)
Next
Close #FF
MsgBox "Your text file has been created."
End Sub
Code:Sub CrText() Dim c00 As Variant Const textFilePath As String = "C:\Desktop\myTextFile.txt" Dim lngCounter As Long Dim FF As Integer FF = VBA.FreeFile c00 = Range("A1").CurrentRegion Open textFilePath For Output As #FF For lngCounter = LBound(c00, 1) To UBound(c00, 1) Print #FF, Join(Application.Index(c00, lngCounter, 0), vbTab) Next Close #FF MsgBox "Your text file has been created." End Sub
textFilePath = CStr(VBA.CurDir) & "\mTextFile.txt"
Sub CrText()
Dim c00 As Variant
Dim textFilePath As String
Dim lngCounter As Long
Dim FF As Integer
textFilePath = CStr(VBA.CurDir) & "\mTextFile.txt"
FF = VBA.FreeFile
c00 = Range("A1").CurrentRegion
Open textFilePath For Output As #FF
For lngCounter = LBound(c00, 1) To UBound(c00, 1)
Print #FF, Join(Application.Index(c00, lngCounter, 0), vbTab)
Next
Close #FF
Workbooks.OpenText textFilePath
End Sub
thanks this is very useful. However, the macro will be used by a number of users and they don't necessarily have a C: drive which could lead to errors. I don't need the text file to be saved anywhere - just appear in front of users. Could we amend this detail please?
@andrew: thanks i am already learning how to use the recorder !
x