SunnyX
asked on
How to copy past data from excel sheet to txt file
Let there is table (please take a look in attachment "for forum" ). I need to write VBA code that makes txt file and copy past needed data to this txt file. ( please take a look in attachment output txt file "testing " )
Many thx in advance !
For-forum.xlsx
testing.txt
Many thx in advance !
For-forum.xlsx
testing.txt
Alternatively with the Excel file and Notepad open. Select the required data on the Excel sheet and Copy. Go to Notepad and just paste. Save notepad file, will be txt by default.
Thanks
Rob H
Thanks
Rob H
Try this
Option Explicit
Sub test()
Dim TempSht As Worksheet
Dim rRng As Range
Dim sFullPath As String
sFullPath = ThisWorkbook.Path & Application.PathSeparator
With Sheet1
Set rRng = .Range(.Cells(8, 2), .Cells(.Rows.Count, 7).End(xlUp))
End With
Set TempSht = Sheets.Add
rRng.Copy TempSht.Range("A1")
TempSht.Copy
ActiveWorkbook.SaveAs Filename:=sFullPath & "testing.txt", FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = False
TempSht.Delete
ActiveWorkbook.Close True
Application.DisplayAlerts = True
End Sub
ASKER
@Roy_Cox,
Thx you so much. However, in my file separation between data row is tabulation and your code makes separation by comma. Could you tell me what I should change in order to make separation by tabulation ("Tab" key in the keyboard ). This is crucial for me because, before my request, I start to form my data base by using tabulation as separation.
Many thx in advance.
Thx you so much. However, in my file separation between data row is tabulation and your code makes separation by comma. Could you tell me what I should change in order to make separation by tabulation ("Tab" key in the keyboard ). This is crucial for me because, before my request, I start to form my data base by using tabulation as separation.
Many thx in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thx u so much !
I'm pleased it helped
On a separate tab use formula to copy the data from the columns required, eg:
A1 =Sheet1!B8
Copied across until you get to the column for the date and time and make that:
=TEXT(Sheet1!G8,"mm/dd/yyy
Copy down as many rows as required.
With this sheet selected do a File - Save As and choose TXT in the File type list. Only the visible sheet will be saved and it will be text values as required.
Thanks
Rob H