+ Reply to Thread
Results 1 to 2 of 2

change format word text by vba in excel

  1. #1
    Registered User
    Join Date
    01-14-2012
    Location
    spain
    MS-Off Ver
    Excel 2010
    Posts
    1

    change format word text by vba in excel

    Good night
    Sorry, but my english is not so good
    I´m trying by vba code in excel, export same cells to word, this i gat it
    But now I want to change the format, change the bold an center the text but i can´t
    Could you help me please??
    Thank you very much
    this is my code

    Dim Tag As String
    Dim varDoc As Object
    Dim a As String
    Dim b As String
    Dim c As String
    Dim d As String
    Dim e As String
    Dim objSelection As Object

    Tag = InputBox("Ingrese TAG")
    Range("D2").Select


    Set varDoc = CreateObject("Word.Application")

    varDoc.Visible = True
    'Sheets("Sheet1").Range("A1:B1").Copy
    varDoc.Documents.Add
    'varDoc.Selection.Paste
    'varDoc.activedocument.SaveAs ThisWorkbook.Path & "/" & "testWord.doc"
    'varDoc.documents.Close

    'varDoc.Quit
    Application.CutCopyMode = False
    Set objSelection = varDoc.Selection


    With objSelection
    ' formato de fuente para el título
    .Font.Name = "Verdana"
    .Font.Size = "16" ' tamaño
    .Font.Bold = True

    .TypeText "INFORME HISTORICO DE EQUIPO" ' agrega
    ' agrega dos parrafos
    .TypeParagraph
    .TypeParagraph

    ' formato para el texto del parrafo 1
    .ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Font.Size = "12"
    .Font.Color = vbBlue ' color de la fuente
    ' método TypeText para escribir el texto
    Do Until Selection.Value = ""
    b = Selection.Value
    If b = Tag Then

    a = Selection.Offset(0, -3).Value
    c = Selection.Offset(0, 1).Value
    d = Selection.Offset(0, -3).Value
    e = Selection.Offset(0, -3).Value
    varDoc.Selection.InsertAfter a
    varDoc.Selection.InsertAfter " "
    varDoc.Selection.moveright
    varDoc.Selection.InsertAfter c
    varDoc.Selection.InsertAfter " "
    varDoc.Selection.moveright
    varDoc.Selection.TypeParagraph
    Selection.Offset(1, 0).Select
    Else
    Selection.Offset(1, 0).Select
    End If

    Loop
    .Font.Color = vbBlack
    .Font.Size = 8
    .Font.Bold = True
    .TypeText "Documento creado el : " & Date
    End With

    varDoc.Selection.Font.Size = 20
    varDoc.Selection.InsertAfter "INFORME HISTORICO DE EQUIPO"
    varDoc.Selection.WholeStory
    varDoc.Selection.Font.Bold = wdToggle
    varDoc.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    varDoc.Selection.moveright
    varDoc.Selection.TypeParagraph
    varDoc.Selection.InsertAfter Tag
    varDoc.Selection.moveright
    varDoc.Selection.TypeParagraph
    varDoc.Selection.TypeParagraph
    varDoc.Selection.Font.Size = 14
    varDoc.Selection.Font.Bold = wdToggle
    varDoc.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    varDoc.Selection.InsertAfter "ORDEN TRABAJO "
    varDoc.Selection.InsertAfter "DESCRIPCION "
    varDoc.Selection.moveright
    varDoc.Selection.TypeParagraph

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: change format word text by vba in excel

    Welcome to the forum, sroque.

    Please take a few minutes to read the forum rules, and then edit your post to add CODE tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1