4 Replies - 5225 Views - Last Post: 01 December 2012 - 01:00 PM Rate Topic: -----

#1 henrikl2000  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 21-February 10

How to change font in MS Word bookmark

Posted 22 November 2012 - 01:33 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: How to change font in MS Word bookmark

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How to change font in MS Word bookmark

Posted 22 November 2012 - 11:26 AM

Don't know that one offhand, sorry. Are you getting errors or does it just not work?

Please read the watermarks in the reply box and use code tags as explained there.
Was This Post Helpful? 0
  • +
  • -

#3 henrikl2000  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 21-February 10

Re: How to change font in MS Word bookmark

Posted 23 November 2012 - 12:44 AM

Hi thanks for your reply,

No I don't get any errors it just doesn't work.
I will use code tags next time. Thank you.
Was This Post Helpful? 0
  • +
  • -

#4 henrikl2000  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 21-February 10

Re: How to change font in MS Word bookmark

Posted 23 November 2012 - 01:38 AM

Hi Bob,

I got it. Searched Google and found a site containing Word VBA code samples for Newbies.
It is very when you know how to.

            
WordDoc.Bookmarks("Test").Select
Selection.Font.size = 36            
Selection.Font.Name = "Segoe UI"            
Selection.Font.ColorIndex = wdRed



Thank you for your effort to help out with VB.
Here is a link to the site : http://www.thezcorp....odeSamples.aspx
Was This Post Helpful? 1
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How to change font in MS Word bookmark

Posted 01 December 2012 - 01:00 PM

Thanks for posting your solution. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1