dj44
02-28-2016, 08:06 PM
Folks,
a very good day and evening to all.:)
I found this very good macro that I wanted to use, but even then I managed to jumble it all up.
I will tell you the quick story.
One time I lost all my macros - now that was a disaster.
So Ive put them in a text file for safe keeping.
I need to split them now as I was too ambitious and need to use some of them.
So my large text file has all my macros in them.
I wanted to split them and rename them with the original sub heading - that becomes the name of the file
Sub DeleteSheets() >> DeleteSheets.txt
Sub MergeWorkbooks() >> MergeWorkbooks.txt
etc
http://www.vbaexpress.com/forum/showthread.php?32361-Extract-to-multiple-text-files
Sub SplitATextFileintoIndividualOnes()
Found on the forum - to split the text file
'http://www.vbaexpress.com/forum/showthread.php?32361-Extract-to-multiple-text-files
Dim tName As String
Dim fName As String
Dim Pth As String
Dim fs, f, a
Dim txt As String
Dim i As Long
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Pth = ActiveWorkbook.Path & "\"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(Pth & "DJImportantMacros.txt", ForReading) ' My macro file is here
txt = f.ReadAll
f.Close
Set f = Nothing
a = Split(txt, "Sub ") & ' Each macro name will be the file name of the text file
For i = 1 To UBound(a)
fName = Trim(Split(a(i), "Sub")(0))
fName = Left(fName, Len(fName) - 2) & ".txt" ' take off the () from the left
Set f = fs.CreateTextFile(Pth & fName, True)
f.write "Sub" & a(i)
f.Close
Next
Set f = Nothing
Set fs = Nothing
End Sub
I tried the shell scripts found on the stack, but they didn't work, then i tried the bat file, and some cmd code , so had a long arduous Sunday trying to split these dratted files, to no fruition :mad:
I looked for text splitter software but found zilch.
I don't understand - don't people split text files? :confused:
If any good person can help this case - I am very grateful
thanks folks and every one have a good Monday :)
my gratitude for your good grace
DJ
a very good day and evening to all.:)
I found this very good macro that I wanted to use, but even then I managed to jumble it all up.
I will tell you the quick story.
One time I lost all my macros - now that was a disaster.
So Ive put them in a text file for safe keeping.
I need to split them now as I was too ambitious and need to use some of them.
So my large text file has all my macros in them.
I wanted to split them and rename them with the original sub heading - that becomes the name of the file
Sub DeleteSheets() >> DeleteSheets.txt
Sub MergeWorkbooks() >> MergeWorkbooks.txt
etc
http://www.vbaexpress.com/forum/showthread.php?32361-Extract-to-multiple-text-files
Sub SplitATextFileintoIndividualOnes()
Found on the forum - to split the text file
'http://www.vbaexpress.com/forum/showthread.php?32361-Extract-to-multiple-text-files
Dim tName As String
Dim fName As String
Dim Pth As String
Dim fs, f, a
Dim txt As String
Dim i As Long
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Pth = ActiveWorkbook.Path & "\"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(Pth & "DJImportantMacros.txt", ForReading) ' My macro file is here
txt = f.ReadAll
f.Close
Set f = Nothing
a = Split(txt, "Sub ") & ' Each macro name will be the file name of the text file
For i = 1 To UBound(a)
fName = Trim(Split(a(i), "Sub")(0))
fName = Left(fName, Len(fName) - 2) & ".txt" ' take off the () from the left
Set f = fs.CreateTextFile(Pth & fName, True)
f.write "Sub" & a(i)
f.Close
Next
Set f = Nothing
Set fs = Nothing
End Sub
I tried the shell scripts found on the stack, but they didn't work, then i tried the bat file, and some cmd code , so had a long arduous Sunday trying to split these dratted files, to no fruition :mad:
I looked for text splitter software but found zilch.
I don't understand - don't people split text files? :confused:
If any good person can help this case - I am very grateful
thanks folks and every one have a good Monday :)
my gratitude for your good grace
DJ