merge cells and save as .txt file

  • Thread starter Thread starter Christof
  • Start date Start date
C

Christof

Hello everyone
well, I'm german and I am a newbie in VBA, so I hope I can describe my
problem as good as necessary.

I got a table (.txt or similiar file) which looks like this:

..blablabla.com
..shalalal.de
..sdölfkh.com
..weaklrfjd.com
..sdfjlöajf.com
..waefasdf.de
..lwöeakfjl.de
and so on (fictive words ;)

afterwards it should look like this:

( url contains ".blablabla.com" or url contains ".shalalal.de" or url
contains... .de )

Now i got two problems. This text-transformation is recurrent, so I
thought creating a userform in Excel would be the best solution. But
how do I merge 2 cells (can't find any help)? And, is there any way to
save the result as a normal .txt file without "extra" quotationmarks??
(like this: "".blablabla.com""). Because I think saving it as a .prn
file and renaming it can't be a sufficient solution.

I would be really grateful for every help!!

Greets, Christof
 
Christof

It may be easier to do this with Excel's text file commands rather than
putting those url's into a spreadsheet. This example macro opens the text
file, manipulates the strings and writes out to a new textfile. It doesn't
use the spreadsheet at all, just VBA.

Sub MakeURLText()

Dim FName As String
Dim Fnum As Long
Dim NewText As String
Dim MyURL As String

FName = "C:\Dick\ng\oct\oldurl.txt"
Fnum = FreeFile

NewText = "("

Open FName For Input As Fnum

Do While Not EOF(Fnum)
Line Input #Fnum, MyURL

NewText = NewText & "url contains " & Chr(34) _
& MyURL & Chr(34) & " or "
Loop

Close Fnum

NewText = Left(NewText, Len(NewText) - 4) & ")"

FName = "C:\Dick\ng\Oct\NewURL.txt"
Fnum = FreeFile

Open FName For Output As Fnum

Print #Fnum, NewText

Close Fnum

End Sub
 
thx a lot
this is indeed a much easier solution!!

works perfectly!!!

Greets, Christof
 
Back
Top