Text formatting (justify/centered) using Microsoft Word macros and Visual Basic || Formateo de texto (justificado/centrado) mediante macros de Word y VB

avatar

This time, we will see some other applications of Word macros to the formatting of our posts. In the previous publication, we could see how to apply macros to change the format of our text (bold letter, italics, subtitle, subscript, red letter, etc.). I invite you to review it, since there are the basics of this publication.

macro word texto.gif

When formatting our posts, that is, adding the necessary code to acquire certain features, it is also necessary to modify its general shape, such as: centered, justified or left/right alignment.

Following the steps of the previous publication for the creation of macros and assign them to a button in the Quick Access Toolbar at the top, we will perform the process of recording a macro, writing the HTML code needed to justify a text:

justificado macro word.gif
Translation: justificado=justified.

The number of spaces between the <div class='text-justify'> and </div> is arbitrary. By assigning this macro to a button (the procedure for this is in the previous post), you can observe its execution in the following animation:

justificado macro word escribiendo.gif
Translation: starting to write.

When checking the Visual Basic (we can enter directly with the key combination ALT+F5), we can observe the generated code:

Sub justificado()

    Selection.TypeText Text:="<div class='text-justify'>"
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeText Text:="</div>"

End Sub

Selection.TypeParagraph represents adding a space with the ENTER key, and the number of times it appears has been arbitrarily assigned when creating the macro. More spaces could be added or removed depending on how you want to modify the macro.


If we want something different, like centered text or right-aligned text, we only have to create another command or "Sub" in Visual Basic, copying the code we have obtained above and modifying it, and then adding the new macro to a different button in the quick access toolbar:

Right-aligned text

<div class='text-right'> </div>

Sub rightaligned()

    Selection.TypeText Text:="<div class='text-right'>"
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeText Text:="</div>"

End Sub

Centered text

<center> </center>

Sub centeredtext()

    Selection.TypeText Text:="<center>"
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeText Text:="</center>"

End Sub

We could see these macros in the form of buttons like this in the Quick Access Toolbar (you can customize the symbol and the name of the button):

1296.jpg

As you can see, we have added a button to add the justified text code, another for right-aligned text, and another for centered text.

In this way, we have in our Word the buttons and macros necessary to enter the HTML code that we need to apply some aspect correction in the text. You do not need to memorize these codes for text alignment, but open your Word and enter them. As I said in the previous publication, this can be useful if you do not have an internet connection to access the Hive editor, or if you are one of those who use Word to create backups of the posts.


Español

En esta ocasión, veremos algunas otras aplicaciones de las marcos de Word al formateo de nuestros posts. En la anterior publicación, pudimos observar cómo aplicar las macros para poder realizar el formateo del aspecto del texto (letra negrita, cursiva, subtítulo, subíndice, letra roja, etc.).

Al momento de formatear nuestros posts, es decir, agregar el código necesario para que adquiera determinadas características, también es necesario modificar su forma general, como puede ser: centrado, justificado o alineación izquierda/derecha.

Siguiendo los pasos de la publicación anterior para la creación de macros y asignarlas a un botón en la barra de herramientas de acceso rápido en la parte superior, realizaremos el proceso de grabar una macro, escribiendo el código HTML necesario para justificar un texto:

justificado macro word.gif

La cantidad de espacios de por medio entre el <div class='text-justify'> y el </div> es arbitraria. Al asignar esta macro en un botón (el procedimiento para esto se encuentra en el post anterior), se puede observar su ejecución en la siguiente animación:

justificado macro word escribiendo.gif

Al revisar el Visual Basic (podemos ingresar directamente con la combinación de teclas ALT+F5), podemos observar el código generado:

Sub justificado()

    Selection.TypeText Text:="<div class='text-justify'>"
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeText Text:="</div>"

End Sub

Selection.TypeParagraph representa agregar un espacio mediante la tecla ENTER, y la cantidad de veces que aparece la hemos asignado arbitrariamente al crear la macro. Podrían agregarse más espacios o quitarlos dependiendo de como quieras modificar la macro.


Si queremos algo diferente, como texto centrado o texto alineado a la derecha, solo debemos crear otro comando o "Sub" en Visual Basic, copiando el código que hemos obtenido arriba y modificarlo, para luego agregar la nueva macro a un botón diferente en la barra de herramientas de acceso rápido:

Texto alineado a la derecha

<div class='text-right'> </div>

Sub alineacionderecha()

    Selection.TypeText Text:="<div class='text-right'>"
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeText Text:="</div>"

End Sub

Texto centrado

<center> </center>

Sub textocentrado()

    Selection.TypeText Text:="<center>"
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeText Text:="</center>"

End Sub

Podríamos ver estas macros en forma de botones así en la barra de herramientas de acceso rápido (puedes personalizar el símbolo y el nombre del botón):

1296.jpg

Tal como se observa, hemos agregado un botón para agregar el código de texto justificado, otro para texto alineado a la derecha, y otro para texto centrado.

De esta manera, tenemos en nuestro Word almacenados los botones y macros necesarios para introducir el código HTML que nos hace falta para aplicar cierta corrección de aspecto en el texto. No hace falta memorizarse estos códigos para la alineación de texto, sino abrir nuestro Word e introducirlos. Como dije en la publicación anterior, esto puede ser útil si no dispones de conexión a internet para acceder al editor de Hive, o si eres de los que utiliza Word para crear respaldos de los posts.


¡Gracias por visitar!..¡Thanks for visiting!

Posted with STEMGeeks



0
0
0.000
3 comments
avatar

Manually curated by EwkaW from the @qurator Team. Keep up the good work!

0
0
0.000
avatar

Thanks for the support.

0
0
0.000