Berikut ini adalah cara untuk mengkopi file txt ke dalam workbook yang aktif:
File txt contoh berada di dalam direktori : "D:\Bisa\YC\YC PEMI052015\\MAY-15.txt"
Copy paste kode ini di modul excel.
Dim DestBook As Workbook, SourceBook As Workbook
Dim DestCell As Range
Dim RetVal As Boolean
Dim sFName As String
' Turn off screen updating.
Application.ScreenUpdating = False
Set DestBook = ActiveWorkbook
Set DestCell = Range("A1")
Workbooks.OpenText FileName:="D:\Bisa\YC\YC PEMI052015\\MAY-15.txt"
Set SourceBook = ActiveWorkbook
'Copy the contents of the entire sheet containing the text file.
Range(Range("A1"), Range("A1").SpecialCells(xlLastCell)).Copy
DestBook.Activate
DestCell.PasteSpecial Paste:=xlValues
Columns("A:Z").EntireColumn.AutoFit
'Close the book containing the text file.
SourceBook.Close False
End Sub
File txt contoh berada di dalam direktori : "D:\Bisa\YC\YC PEMI052015\\MAY-15.txt"
Copy paste kode ini di modul excel.
Dim DestBook As Workbook, SourceBook As Workbook
Dim DestCell As Range
Dim RetVal As Boolean
Dim sFName As String
' Turn off screen updating.
Application.ScreenUpdating = False
Set DestBook = ActiveWorkbook
Set DestCell = Range("A1")
Workbooks.OpenText FileName:="D:\Bisa\YC\YC PEMI052015\\MAY-15.txt"
Set SourceBook = ActiveWorkbook
'Copy the contents of the entire sheet containing the text file.
Range(Range("A1"), Range("A1").SpecialCells(xlLastCell)).Copy
DestBook.Activate
DestCell.PasteSpecial Paste:=xlValues
Columns("A:Z").EntireColumn.AutoFit
'Close the book containing the text file.
SourceBook.Close False
End Sub
0 komentar:
Posting Komentar