vikramjeet23
New Member
- Joined
- Mar 14, 2015
- Messages
- 7
Can I please get some help to have a button to export column B to a .txt file
Sub ColumnToTxt1()
Dim s As String, FileName As String, FileNum As Integer
' Define full pathname to TXT file
FileName = ThisWorkbook.Path & "\test.txt"
' Copy range of B column to the clipboard
Range("B1", Cells(Rows.Count, "B").End(xlUp)).Copy
' Copy clipboard text to the 's' variable
With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.GetFromClipboard
s = .GetText
End With
Application.CutCopyMode = False
' Write s to the TXT file
FileNum = FreeFile
If Len(Dir(FileName)) > 0 Then Kill FileName
Open FileName For Binary Access Write As FileNum
Put FileNum, , s
Close FileNum
End Sub
Sub ColumnToTxt2()
Dim s As String, FileName As String, FileNum As Integer
' Define full pathname of TXT file
FileName = ThisWorkbook.Path & "\test.txt"
' Copy range to the clipboard
Range("B1", Cells(Rows.Count, "B").End(xlUp)).Copy
' Copy column content to the 's' variable via clipboard
With New DataObject
.GetFromClipboard
s = .GetText
End With
Application.CutCopyMode = False
' Write s to TXT file
FileNum = FreeFile
If Len(Dir(FileName)) > 0 Then Kill FileName
Open FileName For Binary Access Write As FileNum
Put FileNum, , s
Close FileNum
End Sub