Read 2 files and save in 1 worksheet

pepek112

New Member
Joined
May 24, 2019
Messages
1
https://pastebin.com/raw/YAYfZ99AHello. I have little trouble. Im really green in VBA but i know about it can be dont in VBA.
I have 2 folders with tons of txt
all txt have the same name in 2 folders but having another data.
ex.
Folder1/1.txt
Folder2/1.txt

Folder1/2.txt
Folder2/2.txt
Example Data files:
https://pastebin.com/raw/cvb0WZyR
https://pastebin.com/raw/1m0atp5G

I wanna from first file write 1 line value lastAccountName: In this is example is Pepek112
And from second file. This is long 1 line but i wanna value from
"minecraft:play_one_minute". In this example, Value is 6840269
In a1 will be Pepek112 in A2
6840269

Im tried make something like this

Code:
Private Sub CommandButton1_Click()Dim myFile As String, text As String, textline As String, posName As String
myFile = "C:\Users\pepek\Downloads\userdata\dffc4b44-9be2-3ad5-878f-0a66f3df4982.txt"
Open myFile For Input As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
Do Until EOF(1)
    Line Input [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , textline
    text = text & textline
Loop
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
posName = InStr(text, "lastAccountName")
Range("A1").Value = Mid(text, posLat + 18, 8)
End Sub

But its not work with all filles because with my nick works great but with another make error
Example txt file which make error
https://pastebin.com/raw/YAYfZ99A

For first i got in A1 "Pepek112"
For second file i got in A1 "
stAccoun"

I dont know how to loop all files and how to solve this :X

Regards
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top