Hello,
I have 3 columns C, D and E.
I want to export to txt files every content from column E, where is column D Title of the file, and C is folder. I want to do this all automatically via VBA.
Is it possible?
Thanks!
Hello,
I have 3 columns C, D and E.
I want to export to txt files every content from column E, where is column D Title of the file, and C is folder. I want to do this all automatically via VBA.
Is it possible?
Thanks!
yes, it is
![]()
open range("c").text & "\" & range("d").text for output as #1 print #1,range("e").text close #1
Hope this helps
Sometimes its best to start at the beginning and learn VBA & Excel.
Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
Available for remote consultancy work PM me
I run it. And it asks me To create macro (dialog box), and I click run. And he puts an extra line End Sub. But I dont know where are the folders? Thanks.
I have done what you asked, advise you on how to take the text to the file. If you dont know how to create macros and assign them, i'd start by looking at that.
I think that we are misunderstood. This is a part of the code? I am not IT/ Developer so, any help would be awesome. I need this for work, to be more efficient.
Thanks again.
Did you mean to add just where to save? Something like this:
?![]()
open range("c").text & "\" & range("d").text for output as #1 print #1,range("e").text close #1 myFile = Application.DefaultFilePath & "\Test.txt
That will never work: "c" and "d" are not range references.![]()
open range("c").text & "\" & range("d").text for output as #1
Can you post a few lines from the workbook (or attach a workbook with sensitive data removed) and explain in context what you want to happen?
Entia non sunt multiplicanda sine necessitate
No, you said that the folder was in column c and the filename was in range d, so that is what i have done, so for row 1 it would be => range("c1").text & "\" & range("d1").text
so, the folder name can contains multiple files (associete.txt) and in this file it shall be written: Hello worldHTML Code:
thanks![]()
I didnt know how to attach the fileHTML Code:so here it is, on dropbox.
Ok, I will mention it again. Column C is the name of the folder. (62 or 64 folders it would be). Column D would be the .txt filename. And column E should be in the .txt file.
If I was not clear enough just tell me.
Thanks
A B C D E 1 100106 CCHBC AssocieteHello world
So "Hello World" should be written to C:\CCHBC\Associete.txt?
@shg
Exactly!![]()
@nathansav
I ve tried C1.text..but this is an error "outside procedure"...
Have you put it in a procedure a sub or function?
This is the code. Is it ok?
![]()
Open Range("c1").Text & "\" & Range("d1").Text For Output As #1 Print #1, Range("e1").Text Close #1 Sub m1() End Sub
Untested:
The directory must exist. The files will be created if they don't exist, and overwritten if they do.![]()
Sub cvelle() Dim iRow As Long Dim iFile As Integer Dim sPath As String Dim sFile As String For iRow = 1 To Cells(Rows.Count, "C").End(xlUp).Row iFile = FreeFile With Rows(iRow) sPath = "C:\" & .Range("C1").Value & "\" sFile = .Range("D1").Value & ".txt" Open sPath & sFile For Output As #iFile Print #iFile, .Range("E1").Value Close #iFile End With Next iRow End Sub
This is the code. Is it ok?
![]()
Open Range("c1").Text & "\" & Range("d1").Text For Output As #1 Print #1, Range("e1").Text Close #1 Sub m1() End Sub
@shg thank you very much.
But there is just first row with C,D and E values.
I need for whole sheetmaybe just to put while or for loop?
Again, it's seem to work, but for only one row.
Thanks.
I have also put all the "future folders" (from C column) on C:/ And still I am getting error-code 76 regarding on this line of code@shg, it's working for some folders, and for the other it doesnt.![]()
Open sPath & sFile For Output As #iFile
and it doesnt create all files, just copule of them. I will keep checking in debug mode..it's a partial program I guess :D Thanks on your effort!
Last edited by cvelle89; 08-04-2014 at 09:57 AM. Reason: Additional information
@shg thank you very much. But there's some problem. "run-time error 76"
Path not found?
So, I must create folder? With witch name?
your code: sPath = "C:\" & .Range("C1").Value & "\"
maybe: sPath = "C:\" & .Range("C1").Value & "\
without " at the end?![]()
The name of the directory you want to put the file in, I reckon:![]()
With witch name?
![]()
sPath = "C:\" & .Range("C1").Value & "\" If Len(Dir(sPath, vbDirectory)) = 0 Then MkDir sPath sFile = .Range("D1").Value & ".txt"
No, you need to put it in a function, that you will call. I think you should read about macros & procedures first off.
@shg
Ok I have all the folders, and he filled in just a half in only one folder and that's it. still getting error 76![]()
Error on what line? What was in the cells when it happened? You would be helping yourself if you would be a little more descriptive.
Spend some time reading http://www.cpearson.com/excel/DebuggingVBA.aspx and then we'll talk some more.
Hello. I now see that mz replay didnt reach you.
So, the main problem was that "future" filename had char "/" in the name, because of that program was crushing.
When I did some exchanges (/ replaced with -) program created all ok.
Just one quick question. I noticed that in excel I have some unicode text (example:š đ č ć ). So, is there some line of code that all the .txt files saves as unicode format or UTF-8?
Thank you very much.
You are very polite.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks