6 Replies - 1409 Views - Last Post: 11 May 2013 - 05:23 AM Rate Topic: -----

#1 mpretico  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 16-June 08

Bolding Text in a String

Post icon  Posted 17 July 2008 - 04:06 PM

Hello everyone,

I would greatly appreciate any guidance that any of you can give. I'm using Word 2003 and I have created a form that can inserts a few different lines of text into a bookmark in the footer of the Word file. In the actual Word doc I entered the footer when creating the document and told it what font/size/color I want that so that the plain text my form inserts is automatically formatted. My issues comes in when my footer requires a section of it to be in bold and then go back to normal text.

I'm able to now insert
Jet Aviation Business Jets, Inc. | Aircraft Management | Flight Support
112 Charles A. Lindbergh Drive | Teterboro Airport | Teterboro, NJ 07608 | USA
Tel. +1 201 462 4100 | +1 800 736 8538 | Fax +1 201 624 7338 | www.jetaviation.com

But what I need to be able to do is

Jet Aviation Business Jets, Inc. | Aircraft Management | Flight Support
112 Charles A. Lindbergh Drive | Teterboro Airport | Teterboro, NJ 07608 | USA
Tel. +1 201 462 4100 | +1 800 736 8538 | Fax +1 201 624 7338 | www.jetaviation.com

Is there a command I can give word or some sort of HTML implementation that I can use to make strings bold?
The code below sort of shows how I'm inserting the text

Private Sub CommandButton1_Click()
Dim oBMs As Bookmarks
Dim oRng As Word.Range
Dim pFooter1a As String
Dim pFooter2a As String

Set oBMs = Activedocument.Bookmarks


'	  Set values for strings
pFooter1a = "Test Text"
pFooter2a = "Second Line of Text"


'	  Insert strings into bookmarks in current Word doc
Set oRng = oBMs("Footer").Range

'pFooter1a needs to be bold while pFooter 2a needs to be normal text
oRng.Text = pFooter1a & pFooter2a
oBMs.Add "Footer", oRng


Unload Me
End Sub



The full document is attached.

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Bolding Text in a String

#2 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: Bolding Text in a String

Posted 18 July 2008 - 01:50 AM

Well what you want isn't possible with a textbox. You'll have to use a RichTextbox. Once you add the text you need, you have to select the sections you need to edit. Here's an example:
I've used a RichTextbox called Richtextbox1 and a Button called Button1. Here's the code for the button's click event:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		RichTextBox1.Text = "Jet Aviation Business Jets, Inc. | Aircraft Management | Flight Support" + vbNewLine + "112 Charles A. Lindbergh Drive | Teterboro Airport | Teterboro, NJ 07608 | USA" + vbNewLine + "Tel. +1 201 462 4100 | +1 800 736 8538 | Fax +1 201 624 7338 | www.jetaviation.com"
		RichTextBox1.Select(0, 32)
		RichTextBox1.SelectionFont = New System.Drawing.Font(RichTextBox1.Font, FontStyle.Bold)
End Sub



As you can see, the code selects the first 32 characters of the textbox this corresponds to the string : "Jet Aviation Business Jets, Inc. "
To make this code a little better, lets calculate the length of the string you need to change. We do this by finding the position of the first "|" like so:
Dim len As Integer
len = RichTextBox1.Find("|")


So your code should look like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim len As Integer
		RichTextBox1.Text = "Jet Aviation Business Jets, Inc. | Aircraft Management | Flight Support" + vbNewLine + "112 Charles A. Lindbergh Drive | Teterboro Airport | Teterboro, NJ 07608 | USA" + vbNewLine + "Tel. +1 201 462 4100 | +1 800 736 8538 | Fax +1 201 624 7338 | www.jetaviation.com"
		len = RichTextBox1.Find("|")
		RichTextBox1.Select(0, len - 1)
		RichTextBox1.SelectionFont = New System.Drawing.Font(RichTextBox1.Font, FontStyle.Bold)
End Sub



Hope this helps :)

This post has been edited by Louisda16th: 18 July 2008 - 01:54 AM

Was This Post Helpful? 0
  • +
  • -

#3 RodgerB  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

Re: Bolding Text in a String

Posted 18 July 2008 - 02:30 AM

You may need to create multiple Range objects to do this, one for the text that needs special formatting and the other for the other text (for the method I am attempting to explain anyway). For the text with special formatting, set the Bold property of the object to True.

@Louisda16th: mpretico is interoperating with Word (infact, is this even VB.NET? :P ).
Was This Post Helpful? 0
  • +
  • -

#4 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: Bolding Text in a String

Posted 18 July 2008 - 02:55 AM

Damn! My bad. Read that in a hurry :(
Well here's something on working with word documents:
http://msdn.microsof...7s6(VS.80).aspx

I've worked with them once. But I had a problem with getting pictures in the document:
http://www.dreaminco...h...c=45031&hl=
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3734
  • View blog
  • Posts: 13,054
  • Joined: 12-December 12

Re: Bolding Text in a String

Posted 11 May 2013 - 01:47 AM

Sub TestFeet()
    Dim oBMS As Bookmarks
    Dim oRng As Range
    
    Application.ScreenUpdating = False
    Set oBMS = Activedocument.Bookmarks
    Set oRng = oBMS("Footer").Range
    
    oRng.Text = "Hello you there"
    oRng.Words(1).Bold = True
    oBMS.Add "Footer", oRng
    Application.ScreenUpdating = True
End Sub

Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Bolding Text in a String

Posted 11 May 2013 - 05:05 AM

View PostLitoreallella, on 10 May 2013 - 11:21 PM, said:

Why these private charters are so expensive? What is included in their cost?

Litoreallella, why would you reply to a post from 2008 and then you're reply has nothing to do with programming?
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3734
  • View blog
  • Posts: 13,054
  • Joined: 12-December 12

Re: Bolding Text in a String

Posted 11 May 2013 - 05:23 AM

View PostCharlieMay, on 11 May 2013 - 12:05 PM, said:

Litoreallella, why would you reply to a post from 2008 and then you're reply has nothing to do with programming?

Doh, I missed that. My efforts were for naught :sweatdrop:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1