Saltar al contenido
PROGRAMAR EN VBA MACROS DE EXCEL

Como leer un archivo TXT delimitado por tabulaciones con macro


(adsbygoogle = window.adsbygoogle || []).push({});

En el presente post muestro una macro que permite leer archivos TXT delimitado o separado por tabulaciones, anteriormente se presentó una macro que permite leer archivos TXT y macro que permite leer archivos TXT delimitados por coma o punto y coma, quizás te interese ver dichos post si requieres aprender a leer archivos TXT con macro.

Recomiendo leer un excelente libro sobre Excel que te ayudará operar las planillas u hojas de cálculo, haz click acá, si quieres aprender sobre Excel, en inglés, entonces debes hacer click here. Si lo que necesitas es aprender o profundizar sobre la programación de macros con VBA este es unos de los mejores cursos on line que he visto en internet.

  
El ejemplo de macro denominado como leer un archivo TXT delimitado por macro, se puede descargar desde el final del post, se descargará un archivo comprimido con dos ficheros uno de Excel y otro TXT que es el archivo que usa la macro para poder mostrar el ejemplo, dicho archivo TXT esta delimitado por tabulaciones.

Al abrir un archivo TXT mediante un editor de texto se podrá ver una serie de datos, que a simple vista parece basura, es decir un montón de datos difícil de comprender y sin sentido, no obstante en dicho archivo se encuentra toda la información de las URL de la WEB http://programarexcel.com y las URL del Canal de You Tube donde se encuentran los archivos tutoriales de cada post; sin embargo cuando se ejecuta la macro se puede observar como la macro al leer el archivo TXT delimitado por tabulaciones y se agregan en cada una de las columnas y filas los datos correspondientes.

A modo de plus el ejemplo contenido en este post, contiene todas las URL de la WEB http://programarexcel.com y las URL del Canal de You Tube donde se encuentran los archivos tutoriales de cada post; ello es importante, porque se puede usar a modo de índice ya que cuando se requiere programar una macro o automatizar Excel, se puede consultar este archivo de Excel, encontrar entre los cientos de ejemplos, algún ejemplo parecido a lo que se necesita y en base a ello modificar o adaptar a las necesidades de cada lector, teniendo un vínculo directo a la web para descargar el ejemplo y al canal de You Tube donde siempre se puede ver como funciona la macro y una explicación en detalle del código y funcionamiento de cada ejemplo.

El vídeo que sigue muestra una explicación más detallada y gráfica de la macro presentada, recomiendo observar para una más fácil comprensión de la macro; suscribe a nuestra web desde la parte superior derecha de la página ingresando tu mail y a nuestro canal de You Tube para recibir en tu correo vídeos explicativos sobre macros interesantes, como  por ejemplo formulario que crea un listado de todas las hojas para poder luego seleccionarlasbuscar en listbox mientras escribes en textboxordenar hojas libro excel por su nombreconectar Excel con Access y muchos ejemplos más.

function onYtEvent(payload) {
if (payload.eventType == ‘subscribe’) {
// Add code to handle subscribe event.
} else if (payload.eventType == ‘unsubscribe’) {
// Add code to handle unsubscribe event.
}
if (window.console) { // for debugging only
window.console.log(‘YT event: ‘, payload);
}
}

Código que se inserta en un módulo
Sub opentxtseparadoTabulacion()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
Dim myfile As Variant, cad As String, fila As Long, texto() As String
Dim h, j As Long, fil As Long, col As Long
ruta = ActiveWorkbook.Path
ChDir ruta
myfile = Application.GetOpenFilename(«Archivos Txt (*.txt*), *.txt*»)
If VarType(myfile) = vbBoolean Then Exit Sub
Open myfile For Input As #1
fil = 1
col = 1
Cells.Clear
While Not EOF(1)
Line Input #1, cad
texto = Split(cad, vbTab)
j = UBound(texto)

For h = 0 To j
Cells(fil, col) = fil
Cells(fil, col).Value = texto(h)
col = col + 1
Next h
col = 1
fil = fil + 1
Wend
Close #1
MsgBox («Los datos se leyeron con éxito»), vbInformation, «AVISO»
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

Si te fue de utilidad puedes INVITARME UN CAFÉ y de esta manera ayudar a seguir manteniendo la página, CLICK para descargar en ejemplo en forma gratuita.


(adsbygoogle = window.adsbygoogle || []).push({});

If this post was helpful INVITE ME A COFFEE and so help keep up the page, CLICK to download free example.

Si te gustó por favor compártelo con tus amigos
If you liked please share it with your friends      

Entradas relacionadas

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Comentarios (24)

I know this if off topic but I’m looking into starting my own weblog and was curious
what all is needed to get set up? I’m assuming having a blog like
yours would cost a pretty penny? I’m not very web savvy so I’m not
100% certain. Any suggestions or advice would be greatly appreciated.
Many thanks

Responder

Heya this is somewhat of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML.
I’m starting a blog soon but have no coding
knowledge so I wanted to get advice from someone with experience.

Any help would be enormously appreciated!

Responder

I’m truly enjoying the design and layout of your blog.
It’s a very easy on the eyes which makes it much more pleasant for me to come here
and visit more often. Did you hire out a designer to create your theme?
Great work!

Responder

Does your website have a contact page? I’m having a tough time
locating it but, I’d like to send you an e-mail.
I’ve got some suggestions for your blog you might be interested in hearing.

Either way, great website and I look forward to seeing
it develop over time.

Responder

Pretty section of content. I just stumbled
upon your weblog and in accession capital
to assert that I acquire actually enjoyed account your blog posts.
Any way I will be subscribing to your augment and even I achievement you access
consistently rapidly.

Responder

This is really interesting, You are a very skilled
blogger. I have joined your rss feed and look forward to seeking more of your
fantastic post. Also, I have shared your website in my social networks!

Responder

You could certainly see your skills within the work you write.
The arena hopes for more passionate writers like you who aren’t afraid to say
how they believe. All the time go after your heart.

Responder

What’s up mates, its fantastic paragraph about tutoringand fully explained, keep it up all the time.

Responder

What’s up, after reading this awesome article i am also happy to share my experience here with colleagues.

Responder

obviously like your web-site however you have to take
a look at the spelling on quite a few of your posts. Several
of them are rife with spelling problems and I to find it very
troublesome to inform the truth on the other hand I will definitely come again again.

Responder

These are really impressive ideas in concerning blogging.

You have touched some good things here. Any way keep up wrinting.

Responder

Hi! Would you mind if I share your blog with my
twitter group? There’s a lot of people that I think would really appreciate your content.
Please let me know. Cheers

Responder

Thanks in favor of sharing such a good idea, paragraph is fastidious, thats why i have read it completely

Responder

It is appropriate time to make some plans for the future and it’s time to be happy.

I’ve read this post and if I could I desire to suggest you few
interesting things or tips. Maybe you can write next articles referring to this article.
I desire to read more things about it!

Responder

It’s a pity you don’t have a donate button! I’d definitely donate to
this fantastic blog! I guess for now i’ll settle for book-marking and adding your RSS feed
to my Google account. I look forward to brand new updates and will
talk about this blog with my Facebook group. Talk soon!

Responder

hello there and thank you for your info – I have definitely picked up something new from right here.
I did however expertise some technical points using this website,
since I experienced to reload the website many times previous to I could get it to load
correctly. I had been wondering if your web hosting is OK?
Not that I am complaining, but sluggish loading instances times will often affect your placement in google and
could damage your quality score if ads and marketing with Adwords.
Anyway I’m adding this RSS to my e-mail and can look out for a lot
more of your respective interesting content. Make sure you
update this again soon.

Responder

Hi! I know this is kind of off topic but I was wondering
which blog platform are you using for this site? I’m getting sick and tired of WordPress because I’ve had problems with hackers and I’m looking at options for another platform.
I would be great if you could point me in the direction of
a good platform.

Responder

Hey there just wanted to give you a quick heads up.

The words in your article seem to be running off the screen in Safari.

I’m not sure if this is a format issue or something to do with web
browser compatibility but I figured I’d post to let you know.
The layout look great though! Hope you get the issue solved soon.
Thanks

Responder

I love looking through an article that can make people think.
Also, many thanks for allowing me to comment!

Responder

WOW just what I was looking for. Came here
by searching for 카지노사이트

Responder

Just desire to say your article is as astonishing.
The clearness in your post is just excellent and i can assume
you are an expert on this subject. Fine with your
permission allow me to grab your RSS feed to
keep up to date with forthcoming post. Thanks a million and please carry on the rewarding work.

Responder

Thanks for the marvelous posting! I truly enjoyed reading it,
you might be a great author. I will be sure to
bookmark your blog and definitely will come back sometime soon. I want to encourage you to continue
your great job, have a nice holiday weekend!

Responder

Hello There. I found your blog the usage of msn. This is
a very well written article. I’ll make sure to bookmark it and come back to read extra of
your useful information. Thanks for the post. I’ll certainly comeback.

Responder

What’s up Dear, are you actually visiting this website
daily, if so after that you will without doubt obtain fastidious
knowledge.

Responder