A1VBCode Forums

How to change font in MS Word using VB6


http://www.a1vbcode.com/vbforums/Topic31764.aspx

By henrikl2000 - 11/21/2012

I am using VB6 to create an application that uses MS Word 2010 to print labels. My question is how do I change the font size, name etc. in a Word Bookmark that is inside a textfield (shape). I can change the font in a plain document but not if the bookmark is inside a textfield.

 

I have been trying the following code:

 

If doc.Bookmarks.Exists("Barcode1") Then

    If doc.Bookmarks("Barcode1").Range.Font.Size = MultiSelection Then

        ' the range of the bookmark consists of runs with different font sizes

        doc.Bookmarks("Barcode1").Range.Font.Size = 20

    Else

        doc.Bookmarks("Barcode1").Range.Font.Size _

            = doc.Bookmarks("Barcode1").Range.Font.Size + 4

    End If

End If

 

And this too:

 

    Dim WordObj As Word.Application

    Set WordObj = CreateObject("Word.Application")

 

    Dim objWord As Word.Document

    Set objWord = WordObj.Documents.Open(FileName:=App.Path & "\LabelLayout\test.docx") '" & SelectedLabelLayout & ".docx")  '"C:\Users\Henrik\Documents\L7159test.docx") 'Test.docx")

   

    WordObj.Visible = True

    With objWord.Bookmarks

        .Item("Barcode1").Range.Text = txtEtiket(0).Text 'txtName

        .Item("Barcode1").Range.FormattedText.Font.Name = "Segoe UI" 'Font.Color = wdColorRed

        .Item("Barcode1").Range.FormattedText.Font.Size = "16"

  End with

By zack - 11/22/2012

Have you tried changing the default settings that are used when you insert a shape or text box in your Word document?

Look at this and scroll down to the Word section.



http://office.microsoft.com/en-us/word-help/set-new-formatting-defaults-for-a-shape-or-text-box-HA010244963.aspx#BMwo>