![]() |
Opening & Reading file in notepad then pasting into excel using VB
Thanks for the replys
Yes that code opened the variable perfectly thanks :) im curious on this 'ReadLine' code, would this be able to read the text in the notepad and paste contents into excel cells the way i need it to? Also there are parts like MR A B, these would need to be trimmed down to just the characters and pasted into cells. Thanks again. |
Opening & Reading file in notepad then pasting into excel usin
Sorry, I missed the part in your post where you said you wanted to read the
text file and paste into Excel. I couldn't clearly understand the logic based on your sample data and expected output.. but it looks like you'll need to code your own parsing logic and then paste into Excel. So, maybe something like this could get you started. The code below will read the text file one line at a time and then paste each line in column A of a new sheet... you'll need to tweak the code so that you can parse each line and put each piece in the right place. Sub test() Dim gff_location As String Dim oFSO As Object Dim ts As Object Dim strLine As String Dim lRow As Long gff_location = "C:\sample.txt" Set oFSO = CreateObject("Scripting.FileSystemObject") lRow = 1 If oFSO.FileExists(gff_location) Then 'read the text file Set ts = oFSO.OpenTextFile(gff_location) 'create a new worksheet 'the new sheet will become the active one Sheets.Add While Not ts.AtEndOfStream strLine = ts.ReadLine 'you need to parse the line according to 'your logic first before 'putting them in the worksheet 'this sample just puts each line in column A ActiveSheet.Range("A" & lRow).Value = strLine lRow = lRow + 1 Wend Else MsgBox gff_location & " file not found!" End If End Sub -- Hope that helps. Vergel Adriano "DJ MC" wrote: Thanks for the replys Yes that code opened the variable perfectly thanks :) im curious on this 'ReadLine' code, would this be able to read the text in the notepad and paste contents into excel cells the way i need it to? Also there are parts like MR A B, these would need to be trimmed down to just the characters and pasted into cells. Thanks again. |
Opening & Reading file in notepad then pasting into excel usin
Thanks for the help it worked nicely and gave good grounds to carry on
with. im now putting line contents into its cells no problem, its just the .GFF file seems to always be on top of the excel sheet, is there any way of putting this in the background and still reading from it? i have a date checker in place which checks the date on a spacific line, if the date in the file is less than the current date a yes/no box appears, the user cannot see this box as the .GFF file is still as the front of the screen. Application.ScreenUpdating = False doesnt seem to do the trick Thanks again! |
All times are GMT +1. The time now is 11:04 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com