Excel VBA Introduction Part 23 - Text Files (FileSystemObjects)

  Рет қаралды 107,669

WiseOwlTutorials

WiseOwlTutorials

Күн бұрын

If you'd like to help fund Wise Owl's conversion of tea and biscuits into quality training videos you can click this link www.wiseowl.co.uk/donate?t=1 to make a donation. Thanks for watching!
You can buy our Introduction to Excel VBA book here www.lulu.com/shop/andrew-goul...
By Andrew Gould
www.wiseowl.co.uk - The Scripting Runtime Object Library allows you to write VBA code to create, open, read from and write to text files using very simple methods. This video teaches you how to work with tab-delimited and comma-separated value files including how to create them, append data to them and how to read from them. The video also includes a section on using text functions for parsing the contents of a text file and the final section talks about combining these techniques with workbook events to create a simple change log.
Visit www.wiseowl.co.uk for more online training resources in Microsoft Excel, Microsoft Access, Microsoft PowerPoint, Microsoft Word, Microsoft Project, Microsoft Publisher, Microsoft Visio, SQL Server, Reporting Services, Analysis Services, Integration Services, Visual Studio, ASP.NET, VB, C# and more!

Пікірлер: 101
@rayearth9760
@rayearth9760 Жыл бұрын
It's 2022 and the knowledge and methods presented in this vid are still absolutely brilliant! Thanks a lot man!
@WiseOwlTutorials
@WiseOwlTutorials Жыл бұрын
Happy to hear it's still useful, thanks for watching!
@deninsrmic4165
@deninsrmic4165 Жыл бұрын
@@WiseOwlTutorials it is indeed, your tutorials especially on FSO and string functions which are to come later in your videos are very useful. I haven’t come across REGEX in your videos unfortunately, which makes a life much easier when it comes to string parsing and string manipulation, but nevertheless text functions you teach us here are very much of help. I have used Knowledge you presented here on FSO in first part of your tutorial on FSO, for my work project and helped me immensely. If anyone wants to learn VBA this is the right address. Thanks for all the effort and thank you for showing us a real masterpiece of truncating string with a loop before using TextToColumn function. In one of your videos, you have used something similar, but this really induced me to think beyond. Great video, thanks. ☘️🍀👍
@WiseOwlTutorials
@WiseOwlTutorials Жыл бұрын
@@deninsrmic4165 Thanks Denin! Happy to hear that you found several parts of the video useful. RegEx is one of those topics that has been on my list of videos to make for a long time - one day I'll get around to doing it!
@deninsrmic4165
@deninsrmic4165 Жыл бұрын
@@WiseOwlTutorials that would be brilliant Andrew, as surprisingly very little was covered on VBA RegEx, and if so, it was done not very thoroughly and fleetingly. Most tutorials on RegEx object and it’s meta language was done in Java or Python which is to a certain degree applicable to VBA but tutorials on VBA RegEx methods and properties are not covered as much one would expect. Many thanks. 👍
@edparaiso9218
@edparaiso9218 7 ай бұрын
Do you have mentoring?
@johassan6509
@johassan6509 4 жыл бұрын
Awwwe No Andrew we don't hate you! I actually love learning the longer way of doing something and then how you have simplified it. I personally think its the best way to learn.Thanks guys.
@simonreiff3889
@simonreiff3889 Жыл бұрын
This was so helpful! Literally everything I know about VBA is from these tutorials, which have completely transformed my use of Excel for my business. I wrote some additional code, using Regular Expressions, to deal with the special-character problem, and I also gave my variables slightly more relevant names to my own situation. In my particular scenario, I had multiple special characters of a varying quantity arising in columns A and D of my spreadsheet, and those entries included not only commas but also parentheses, hyphens, slashes, etc. I used two cases, one if the current column was 1 or 4 (i.e., in Columns A or D), and one otherwise, and in the 1 or 4 case, I used a separate function that looped over a counter variable that counted how many special characters were in the cell to be transferred to the CSV file, encasing each one inside double-quotation marks. Finally, I put a button on the spreadsheet, and added three lines of code (e.g., (1) sub AddTimeEntry_Click() (2) Call ExportToCSVFile (3) End Sub) to call the sub when the button was clicked. My code executes in about 0.1 seconds, so quickly that I had to put in a message box to alert me that the CSV file was saved and written because I kept thinking nothing had happened and saving multiple files. Everything is formatted perfectly no matter how many special characters I have in columns A or D!! If it's of assistance to anyone else, here was my solution--thanks again Wise Owl for all your help! Sub ExportToCSVFile() Dim ws_MyTimeSheet As Worksheet Dim fso As Scripting.FileSystemObject Dim DestinationFolder As String Dim ts As Scripting.TextStream Dim TimeEntryRow As Range Dim ColCount As Integer Dim CurrentColumn As Integer Set ws_MyTimeSheet = ThisWorkbook.Worksheets("MyTimeSheet") Set fso = New Scripting.FileSystemObject DestinationFolder = [REDACTED--INSERT YOUR FILE ADDRESS HERE AND REMEMBER THE BACKSLASH \] Set ts = fso.CreateTextFile(DestinationFolder & Format(Now, "mmddyyyy_hhmmss") & "_upload.csv", True) Application.ScreenUpdating = False ws_MyTimeSheet.Activate ColCount = Range("A1", Range("A1").End(xlToRight)).Cells.Count For Each TimeEntryRow In Range("A1", Range("A1").End(xlDown)) For CurrentColumn = 1 To ColCount Select Case ColCount Case 1 Or 4 ts.Write """" & EncodeValue(TimeEntryRow.Cells(1, CurrentColumn).value) & """" Case Else ts.Write EncodeValue(TimeEntryRow.Cells(1, CurrentColumn).value) If CurrentColumn < ColCount Then ts.Write "," End Select Next CurrentColumn ts.WriteLine Next TimeEntryRow ts.Close Set fso = Nothing MsgBox "Your time entries have been saved to a CSV file and are ready to be uploaded!" End Sub Function EncodeValue(ByVal value As Variant) As String Dim regEx As Object Set regEx = CreateObject("VBScript.RegExp") 'late binding so users don't have to enable the library for Regular Expressions regEx.Global = True 'We want all instances of special characters in our worksheet to be encoded, so set this to True regEx.Pattern = "[,""()\-\;\/\.\']" 'For each instance of the special character in the cell in our worksheet... If regEx.Test(value) Then '....put the special character in double-quotation marks EncodeValue = """" & regEx.Replace(value, "$&") & """" Else EncodeValue = value End If End Function
@WiseOwlTutorials
@WiseOwlTutorials Жыл бұрын
Excellent work! Thanks for taking the time to share your solution - I'm sure that others will find it helpful!
@simonreiff3889
@simonreiff3889 Жыл бұрын
@@WiseOwlTutorials Thanks so much!
@marcip1456
@marcip1456 7 жыл бұрын
Thanks for another great video! I love that you teach the longer methods first, then the faster ones. It really helps me to troubleshoot my code! If the short version doesn't work, I try the long version. If that succeeds, I know I probably missed some specific formatting in the short version, and if it doesn't, it's generally easier to pinpoint what is causing my problem!
@b.petrushchak
@b.petrushchak 9 жыл бұрын
Thank you for an interesting video!!! If somebody is just starting to work with text files, this video is everything one might need to master the functionality.
@simoneandreagalli6968
@simoneandreagalli6968 5 жыл бұрын
Been looking at your video, like 10 more or less, in like 2 years. I am now proficient with VBA but I keep finding your video always satisfactory and always finding something to learn and which is useful. You deserve way more views and thumbs. Just having to deal with xls/xlsx/csv file at work, and wanted to "cache" the csv text and use only some of the data without opening all the csv file to a workbook . I've used "Open file for mode as filenumber" method and find it to work as needed. Something I just wanted to point out is that some file may be generated by non windows users. This the newline character is not CRLF but only LF, this is to know as it will change the way you have to deal with the file to read just 1 line.
@michaelhenderson5098
@michaelhenderson5098 4 жыл бұрын
Just found your video. Thanks for the tutorial. I have adapted it to my workbook, and it is working as advertised.
@krn14242
@krn14242 9 жыл бұрын
Genius. Thanks so much. Finally found an excellent resource for advanced excel VBA topics.
@asim57786
@asim57786 6 жыл бұрын
thank you so very much!!! I hope you make lots of money and be very happy in your life :D
@CyrusPieris
@CyrusPieris 4 жыл бұрын
Hi, Thank you for the great classes. Is there a course specifically about extracting xml data.
@kapibara2440
@kapibara2440 Жыл бұрын
Many thank for the content! Top quality 😃 Great teaching style.
@WiseOwlTutorials
@WiseOwlTutorials Жыл бұрын
Thanks for the kind comments and for watching!
@vasileiosgeorgakopoulos2362
@vasileiosgeorgakopoulos2362 6 жыл бұрын
thank you for you excellent tutorials!! i have one question: does this work for multiple txt. file in a folder? many thanks!
@tamoghnaacharyya7212
@tamoghnaacharyya7212 10 жыл бұрын
Dear Andrew, wow fantastic tutorial series on excel VBA!!!...crystal clear and probably the most comprehensive excel VBA tutorial channel on you tube ... Have a request ; can you please make available the notes that you are using to teach each concept? Cheers
@tamoghnaacharyya7212
@tamoghnaacharyya7212 10 жыл бұрын
***** I was mentioning the slides that you use in your tutorial. But the articles that you linked are really great....i had a quick look...and go through them... Thanks for your videos! Cheers
@natraj6716
@natraj6716 8 жыл бұрын
Hello Sir, I have used the split function instead of left() & right() (video from 27:00 min on wards) to split the text into array.
@eliaslarsson3964
@eliaslarsson3964 8 жыл бұрын
Very good tutorial. Thank you
@susanharrison5575
@susanharrison5575 9 жыл бұрын
Once again a fantastic video tutorial. You make the tricky look very easy, sign of a true master. Can you make this seem easy I wonder? I want to amend my change log to incorporate the "Before change" cell values. I've figured that I can write all of the range addresses and values to a public array in the SelectionChange event and then loop through that array in the Change event but that seems a trifle convoluted. How would you go about recording the values that have been changed?
@jonathanvillafana5726
@jonathanvillafana5726 5 жыл бұрын
Hi Andrew. I have been following your VBA series, and I just want to thank you for creating such great content! My skills have increase substantially. I would like to request a new subseries to this regarding Shell32 Library, Microsoft Shell Controls And Automation. I have been able to successfully implement Shell32.shell to use ShellExecute function to mass print, and open PDF files, however, I would like to see what this library is capable of doing with a level of expertise you posses. For example, learning some techniques on how to extract data from a PDF file to and excel workbook. Anyways I am a big fan!
@WiseOwlTutorials
@WiseOwlTutorials 5 жыл бұрын
You're very welcome Jonathan! I'm really happy to hear that the videos have helped you, it sounds like you've learnt a lot! I think that you might be overestimating my experience with using Shell in VBA however - I've used it every once in a while to perform some very simple tasks but I suspect that you know more than I do at this point! It's a nice suggestion though and I'll add it to my list of things to research. Thanks so much for your input and for watching!
@jnwte
@jnwte 8 жыл бұрын
I've got some projects in mind where I can use this. Thanks.
@chobblegobbler6671
@chobblegobbler6671 5 жыл бұрын
Hi Andrew..Can you give some info for reading csv files without a "Data start " row and also having "," within each datapoint(cell)
@wagnerjmful
@wagnerjmful 5 жыл бұрын
You are Wizard , spectacular!!
@KwaiTerk
@KwaiTerk 7 жыл бұрын
Awesome video! Not sure if it will be on the next tutorial but what if your text has " " them how to include the " " in the text?ts.writeline " " Data Starts Here" " will error
@pinararas2076
@pinararas2076 6 жыл бұрын
Hi Andrew, thanks for the informative videos, it helps a lot with understanding VBA. I have a question regarding the copying of date into the textfile (+/- min 15 in the video). In the code we don't state that we are copying any cells from the excel. I can see where we are selecting it via range but not the actual copy command. Is this done when writing ts.write r.offset...or somewhere else? This is keeping me busy....
@tinahickshuettemann7433
@tinahickshuettemann7433 7 жыл бұрын
Great videos for someone extremely new to VBA with that being said, I'm hoping that what I'm looking to achieve is possible. I'm creating a form that a user can enter details specific to the data that can be varied, by multi users so if user one completes the form and user 2 completes the form their responses may be different (i.e. form text box states to enter color) user 1 enters yellow yet user two enters blue, then merge it into a static string of details (static details the sky is "form details") (this is not the exact example what I need is more complex I have several form details I'd need to merge into the static string, but I am hoping the color example will give you an idea what I'm attempting to achieve). Do you have a video out there already that shows how to get the form to convert into the text file? I haven't found it yet in my hunt through the videos for the last 3 days and I'm on a time crunch to achieve this endeavor any assistance would be greatly appreciated!!! I did watch the creation of text file, but I'm having a hard time getting it to pull in the details of my form. Currently I do have the form details writing into a worksheet within the excel document, mainly so I could see my form actually working
@sobiakanwal6209
@sobiakanwal6209 8 жыл бұрын
How do I loop through all the folder or files starting with the same phrase only in Microsoft excel vba?
@JI9131
@JI9131 10 жыл бұрын
well done!
@joshrxs_
@joshrxs_ 3 жыл бұрын
Thank you!!
@WiseOwlTutorials
@WiseOwlTutorials 3 жыл бұрын
You're welcome, John! Thanks for watching!
@CelsonFC
@CelsonFC 2 жыл бұрын
Awesome!
@WiseOwlTutorials
@WiseOwlTutorials 2 жыл бұрын
Thanks!
@sharonhoyle2327
@sharonhoyle2327 7 жыл бұрын
I have used the CDate function as described here, but needed to tweek the "vbTab" so that my program recognised the character "|" instead as the delimiter. However, I found a problem in that the value of "0.00" as a number in my text file has been returned as a date "12:00:00 AM" in excel. How can I rectify this please?
@catlover70
@catlover70 9 жыл бұрын
Hello, I have a problem when activating the references in sub menu Tools of VB window. When I click it, a window appears with message "Error accessing the system registry". Do you know why? Is that because of the Excell system or the window system? What should I do? Many Thanks in advance.
@nataliiaiatsenko7779
@nataliiaiatsenko7779 7 жыл бұрын
Thank you, Andrew, for your great tutorial. Unfortunately this code "does not want" to work on Mac. Any idea how to adjust it? Best regards. Nataliia
@nataliiaiatsenko7779
@nataliiaiatsenko7779 7 жыл бұрын
Thanks for your help, Andrew!
@andrewspacie2946
@andrewspacie2946 3 жыл бұрын
how do you change it so it creates a new txt file with the name as the current time and date
@fouad.abujasser
@fouad.abujasser Жыл бұрын
Thank You very much for this absolutely perfect tutorial. One question please: Once we read a line in a text file can we move back to the previous lines ? in other words, Can we move freely in the text file and read lines forward and backward as we like ?
@WiseOwlTutorials
@WiseOwlTutorials Жыл бұрын
Hi Fouad! Sadly not, you can only move forwards in a TextStream object. You might find this video on using ADO to connect to a text file useful kzfaq.info/get/bejne/jJ2Dps962J2scX0.html You can then investigate the various Move methods you can apply to an ADO Recordset object: learn.microsoft.com/en-us/sql/ado/reference/ado-api/move-method-ado?view=sql-server-ver16 learn.microsoft.com/en-us/sql/ado/reference/ado-api/movefirst-movelast-movenext-and-moveprevious-methods-ado?view=sql-server-ver16 I hope it helps!
@fouad.abujasser
@fouad.abujasser Жыл бұрын
@@WiseOwlTutorials Thank you very much. I will watch it. wish you all the best ❤
@peterhontaru5537
@peterhontaru5537 6 жыл бұрын
Absolutely brilliant! Thank you
@luiztunon
@luiztunon 9 жыл бұрын
Ola Wise, Acompanhando a criação deste código tive o seguinte problema: ts.=fso.CreateTExtFile.............& \pasta destino\Nome_Texto.txt "Permissão negada". Como resolvo isso. Obrigado (usei o office 2010)
@tomash9785
@tomash9785 9 жыл бұрын
Hi Andrew when I do this Do Until ts.AtEndOfLine ActiveCell.Value = ts.ReadLine ActiveCell.Offset(1, 0).Select Loop I get just first two rows, then there are ts.WriteBlankLines and it seems to be where this procedure stops
@tomash9785
@tomash9785 9 жыл бұрын
Thank you ! It solved the problem
@Ronnet
@Ronnet 8 жыл бұрын
What if I wanted to read in data from multiple textfiles and combine the data? For example based on a common (key) value shared between both files? Does anybody know of a tutorial on combining data from multiple textfiles?
@jnwte
@jnwte 8 жыл бұрын
Have three streams open (1 for each file and 1 for the output file) and compare line by line or bring the contents of the files into a worksheet and use vlookup to merge.
@bulataobren
@bulataobren 7 жыл бұрын
Hi! Very helpful video thanks! I have a question...how do you read a text file to a one cell only?t.y.
@bulataobren
@bulataobren 7 жыл бұрын
WiseOwlTutorials it worked!yeah👍🏼thanks very much! 😄
@AmbaPrasadReddy
@AmbaPrasadReddy 9 жыл бұрын
Hi Andrew, I have a quick question. Do we always have to activate these libraries in order to create files or folders....or can we do that without activating the libraries?
@AmbaPrasadReddy
@AmbaPrasadReddy 9 жыл бұрын
Okay thanks! You are awesome!
@natraj6716
@natraj6716 8 жыл бұрын
textarray=split(textline,vbtab)
@victoropere2107
@victoropere2107 6 жыл бұрын
amazing
@yashsomaiya8141
@yashsomaiya8141 4 жыл бұрын
Hi I have one question why didn't you make even a single video MS Access macro?
@Elchimbotanito69
@Elchimbotanito69 6 жыл бұрын
Mega Like!
@jitendrakashyap3023
@jitendrakashyap3023 6 жыл бұрын
sir continously showing error ...i dont know how i should rectify it...i just copied ur commands..
@-fet-algeria9095
@-fet-algeria9095 3 жыл бұрын
How to create a text file in utf-8 encoded excel vba Thank you
@WiseOwlTutorials
@WiseOwlTutorials 3 жыл бұрын
You're welcome, StackOverflow is your best friend for questions like this: stackoverflow.com/questions/4125778/unicode-to-utf-8 stackoverflow.com/questions/2524703/save-text-file-utf-8-encoded-with-vba I hope it helps!
@bantidas239
@bantidas239 2 жыл бұрын
Sir how to change particular some words in a text file by the excel
@WiseOwlTutorials
@WiseOwlTutorials 2 жыл бұрын
You can use the Substitute method docs.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.substitute
@andywoolley5954
@andywoolley5954 7 жыл бұрын
I haven't read all the comments and at this point haven't watched the whole video but the date issue can be fixed easily. You need to define another string so Dim datevalue As String datevalue = Format(Date, "dd/mm/yyyy") This will set all dates as a string in the given format.
@andywoolley5954
@andywoolley5954 7 жыл бұрын
WiseOwlTutorials as I said at the point I had not watched the whole video. I'll take the time later today to watch the whole thing. my little snip works for me.
@andywoolley5954
@andywoolley5954 7 жыл бұрын
I and i'm sure others appreciate your commitment to your videos and user responses. Good jod with the videos you've put up. Hope to see more of them!
@andywoolley5954
@andywoolley5954 7 жыл бұрын
WiseOwlTutorials I have subscribed. Happy to help if you need it. Seen good things and good practice so far in your videos
@user-mn2nc6pw5v
@user-mn2nc6pw5v Жыл бұрын
Hi Andrew, Error pulling data from txt to excel, example 67235,12 number is detected as date, I think it gives pre-1900 error, what is the reason and solution? location of error: If IsDate(ThisValue) Then ThisValue = CDate(ThisValue) End If ActiveCell.Value = ThisValue Google translate
@ashokkandukury2870
@ashokkandukury2870 7 жыл бұрын
woooooooohoooooo.....!!!!!!
@ksrinivas1729
@ksrinivas1729 8 жыл бұрын
I have one question I am extracting some data in text file based on criteria TOTALS but in my case code is working only for one TOTALS as my file contains more than one TOTALS I need extract all TOTALS Values ... Unable to loop through code Please advice.... Many Thanks in advance.. Dim myFile As String, text As String, textline As String, entryDescription As String, amount As Long, Filenum As Long, X As Integer Sub Button1_Click() Range("C1").Value = "2425" X = 1 myFile = Application.GetOpenFilename() Open myFile For Input As #1 Do Until EOF(1) Line Input #1, textline text = text & textline Loop If InStr(text, "TOTALS") > 0 Then TOTALS = InStr(text, "TOTALS") Range("A" & X).Value = Mid(text, TOTALS + 31, 25) X = X + 1 End If Close #1
@zubairkahn1983
@zubairkahn1983 2 жыл бұрын
Hi Andrew, thanks again for another super useful video. Based on this video (Part 23), I wrote a code. It works fine. It copies some data from Excel, creates a text file and pastes it there in a pre-defined layout. The code works what I was expecting. The date/time data in Excel is in dd/mm/yyyy hh:mm:ss and I want it to be in dd mmm yyyy hh:mm:ss format. With ts.write r.Value I get same format as in Excel. How can I change it to the desired format? Changing the format in Excel doesn't help. Thank you.
@WiseOwlTutorials
@WiseOwlTutorials 2 жыл бұрын
Hi Zubair! If you've already formatted the Excel cells you can refer to the Text property r.Text rather than r.Value. Alternatively, you can use the Format function to apply any format you like to the Value: ts.Write Format(r.Value, "dd mmm yyyy hh:mm:ss") I hope that helps!
@zubairkahn1983
@zubairkahn1983 2 жыл бұрын
@@WiseOwlTutorials Hi Andrew, thank you sooooo much. It certainly worked.
@WiseOwlTutorials
@WiseOwlTutorials 2 жыл бұрын
@@zubairkahn1983 Excellent!
@zubairkahn1983
@zubairkahn1983 2 жыл бұрын
@@WiseOwlTutorials Another not so needed nitty gritty would be if Dates are all shown in Upper Letters. Currently, month is in mmm. The format I used was DD MMM YYYY HH:MM:SS
@WiseOwlTutorials
@WiseOwlTutorials 2 жыл бұрын
@@zubairkahn1983 Hi Zubair, you can use the UCase function to change text to upper case. UCase("1 jan 2022") will return 1 JAN 2022
@philmillington5025
@philmillington5025 2 жыл бұрын
Hi Andrew Can tell me if its posable to Add a Worksheet to a Workbook and Name the the Worksheet, that I can do, but is it also possable to give the new sheet a Code Name by just using VBA code? Also Is it possable to Import a Module using VBA code. The reson I ask is because I want to create a SetUp for a Workbook with all the Worksheets and Code in Place just using VBA. Regards Phil Millington
@WiseOwlTutorials
@WiseOwlTutorials 2 жыл бұрын
Hi Phil! It is possible to write VBA code to manipulate your VBA project and Chip Pearson has an excellent description of the process here www.cpearson.com/excel/vbe.aspx I'm not sure if it covers importing a module but I hope the background information helps!
@philmillington5025
@philmillington5025 2 жыл бұрын
@@WiseOwlTutorials Hi Andrew Thanks for the info on my recent query I will check out the web site you mentioned and let you know how I got on, Thanks for taking the time to reply, keep up the good work Kind Regards Phil
@philmillington5025
@philmillington5025 2 жыл бұрын
Hi Andrew I had a look at the web site you suggested and it look to much for my little brain a step to far. I think I will automate as much as possible and do the rest manually. Thanks for your help and taking the time to reply. I’ll plod on Regards Phil
@WiseOwlTutorials
@WiseOwlTutorials 2 жыл бұрын
@@philmillington5025 No problem Phil! If it helps, I feel the same when it comes to automating the VB Editor!
@philmillington5025
@philmillington5025 2 жыл бұрын
ps The workbook I want to update already has code in it.
@badassack
@badassack 10 жыл бұрын
Hey, there!! first post, guess i'm the only one with a problem. This works great except, of course, except at 16:30 you tested your code and it wrote the text to your test.txt file beginning just under where you said "data starts here". Mine on the other hand starts writing at the bottom of the page and works it's way up. I swear on everything i did it just like you. why is it always me?
@badassack
@badassack 10 жыл бұрын
Yeah here look... Dim fso As Scripting.FileSystemObject Dim ts As Scripting.TextStream Dim r As Range Dim colcount As Integer Dim i As Integer Set fso = New Scripting.FileSystemObject Set ts = fso.OpenTextFile(Environ("userprofile") & "\desktop\Newtextfile\test.txt", ForAppending) Worksheets("data").Activate colcount = Range("a2", Range("a2").End(xlToRight)).Cells.Count For Each r In Range("a2", Range("a1").End(xlDown)) For i = 1 To colcount ts.Write r.Offset(0, i - 1).Value If i < colcount Then ts.Write vbTab Next i ts.WriteLine Next r ts.Close Set fso = Nothing
@badassack
@badassack 10 жыл бұрын
badassack Oh forget it, friggin thing works now, didn't do anything different, just started completely over and it worked, craziness. By the way , love the new video, so far. The project i'm working on is reliant on your video's. seems like when i need to know something new, you come out with just the right video, thanks alot, talk soon I'm sure.
@sohelahmed526
@sohelahmed526 8 жыл бұрын
Wow
@ugabob1
@ugabob1 9 жыл бұрын
I keep getting an error on the line of that sets the value of ColCount.. anybody spot the issue ? If I simply set ColCount to an integer everything works.. Sub AddDatatoTextFile() Dim fso As Scripting.FileSystemObject Dim r As Range Dim ColCount As Integer Dim ts As Scripting.TextStream Dim i As Integer Set fso = New Scripting.FileSystemObject Set ts = fso.OpenTextFile( _ "C:\$user\WORK\VBA Training\First Folder\Test.txt", _ IOMode:=ForAppending) movielist.Activate 'ColCount = Range("a2", Range("a2").End(xlRight)).Cells.Count ColCount = 4 For Each r In Range("a2", Range("a1").End(xlDown)) For i = 1 To ColCount ts.Write r.Offset(0, i - 1).Value If i < ColCount Then ts.Write vbTab Next i ts.WriteLine Next r ts.Close Set fso = Nothing End Sub
@ugabob1
@ugabob1 9 жыл бұрын
Thank you.. your tutorials are really great.
@bluex5115
@bluex5115 3 жыл бұрын
how can we delete a line from a text file ?
@WiseOwlTutorials
@WiseOwlTutorials 3 жыл бұрын
Hi Gabi, this is probably the easiest way to do it stackoverflow.com/questions/30047644/how-to-delete-a-line-in-a-txt-file-if-number-exists-in-vba
@bluex5115
@bluex5115 3 жыл бұрын
thank u ... seeking on the the net.. the result is that is No way to delete a ROW on a text file... only to copy value on the temp file then delete original and replace.... done
@talaberbalazsgmail
@talaberbalazsgmail 9 жыл бұрын
The second read isn't working. I look step by step, and don't separate the words, just write immediately to the cell (1row - 1cell)
@MEITZIJORAA
@MEITZIJORAA 3 жыл бұрын
Great video, thank you! But god damn you are FAST speaker.
@andreberlin947
@andreberlin947 7 жыл бұрын
Hello. Thanks a lot for your tutorials. But unfortunately - the code doesn't work. I got the message for "Dim fso As Scripting.FileSystemObject" "variable is not defined. Cold you help me please to solve the problem? Best regards AB
Excel VBA Introduction Part 24 - File Dialogs
36:25
WiseOwlTutorials
Рет қаралды 77 М.
Excel VBA Introduction Part 22 - Files and Folders (FileSystemObjects)
48:33
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 8 МЛН
That's how money comes into our family
00:14
Mamasoboliha
Рет қаралды 12 МЛН
WHAT’S THAT?
00:27
Natan por Aí
Рет қаралды 12 МЛН
LOVE LETTER - POPPY PLAYTIME CHAPTER 3 | GH'S ANIMATION
00:15
Get Data from Multiple CSV Text Files into Excel Worksheet
23:58
Dinesh Kumar Takyar
Рет қаралды 10 М.
Parsing text files with VBA
1:12:31
Gove Allen
Рет қаралды 11 М.
Excel VBA Introduction Part 11.2 - Application.InputBox
40:13
WiseOwlTutorials
Рет қаралды 131 М.
7 Simple Practices for Writing Super-Readable VBA Code
13:03
Excel Macro Mastery
Рет қаралды 67 М.
25 Nooby VBA Habits You Need to Ditch Right Now
8:42
Excel Macro Mastery
Рет қаралды 22 М.
Excel VBA Introduction Part 39 - Dictionaries
26:24
WiseOwlTutorials
Рет қаралды 59 М.
How to Combine Multiple Excel Files using VBA
19:06
Excel Macro Mastery
Рет қаралды 32 М.
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 8 МЛН