How can I format a word document, from MS Visual Basic?

1

Cordial greeting colleagues, it turns out that I am generating a word file from a button that is in a form, in MS Visual Basic, I generate the document with the text that I entered, saved and opened automatically, my question is how do I add format to that text that I am entering from visual basic, for example: the hello world that I am entering that comes out with Arial font 20, with bold, centered and if I add another text more, give it a different format, I would also like to know how to add an image from there with centered alignment.

Here I attach my code

'Se agrega la libreria para manejar aplicaciones word 
'Se agrega la referencia al proyecto de microsoft word object library
Imports Microsoft.Office.Interop

Public Class Form1
    Private Sub btncrear_Click(sender As Object, e As EventArgs) Handles btncrear.Click
        'Declara la variable.
        Dim objWD As Word.Application
        'Crea una nueva instancia de Word
        objWD = CreateObject("Word.Application")
        'Agrega un nuevo documento en blanco
        objWD.Documents.Add()
        'Agrega Texto.
        objWD.Selection.TypeText("Hola mundo")
        'Guarda el documento
        objWD.ActiveDocument.SaveAs(FileName:="cotizacion.doc")
        'Declaramos la variable para abrir el documento y se le asigna el valor al objeto y especificamos el nombre del documento a abrir
        Dim archivoWord = objWD.Documents.Open(FileName:="cotizacion.doc")
    End Sub
End Class
    
asked by Kevin Burbano 24.01.2018 в 02:35
source

1 answer

0

What you should do is use the property Font of Selection to modify the parameters you want from source. For example:

objWD.Selection.Font.Name = "Lucida Console"
objWD.Selection.Font.Size=12
    
answered by 24.01.2018 / 16:33
source