Place formatted Text in Shape(textbox)

  • Thread starter StevenD72 via OfficeKB.com
  • Start date
S

StevenD72 via OfficeKB.com

I created a "textbox" on my worksheet that I fill with data from another
worksheet. The textbox is a "shape". I am able to place text in the box
without any problems, however I want a few of the items to be BOLD when I
place them. I do not want all the text to be that way.

Is there a way to do this within VB?

I can select the information with the mouse and press the BOLD button on the
commandBar and it does work, so I am guessing there should be a way to do
this in VB. I am trying to "paste" the items that came from the worksheet as
BOLD.

***some of the code has been removed because it was more than needed.***

Thanks Again.

Steve
'-----------------------------------------------------------------------------


Sub Fill_Letter()

Dim ws As Worksheet
Dim ws2 As Worksheet
Set ws = Worksheets("Billing Letter")
Set ws2 = Worksheets("Billing Statement")

'Get Info from Billing Statement

Con_Name = ws2.Cells.Range("D12").Value
Con_Comp = ws2.Cells.Range("E11").Value
Con_Addrs = ws2.Cells.Range("C13").Value
Con_City = ws2.Cells.Range("B14").Value

'Place Header on page
ws.DrawingObjects("HeaderBox").Select
Selection.Characters.Text = "THIRD DISTRICT CHIEF'S ASSOCIATION"

'Place main letter on Page
ws.DrawingObjects("Textbox2").Select

Sdate = FormatDateTime(Date, vbLongDate) 'Gets Todays Date

Selection.Characters.Text = Sdate & Chr(10) & Chr(10) _
& Con_Name & Chr(10) & Con_Comp & Chr(10) _
& Con_Addrs & Chr(10) & Con_City & ", " _
& Con_State & " " & Con_Zip & Chr(10) & Chr(10) _
& "This statement is for services provided by the Hazardous Materials
Team"
End Sub
 
P

papou

Hi Steve
You can use the Characters method:

Sub Test()
With Worksheets("Sheet1").Shapes("Text Box 1").TextFrame
..Characters.Text = "sample text"
'the word "text" in bold (need to count characters)
..Characters(8, 4).Font.Bold = True
End With
End Sub

HTH
Cordially
Pascal
 
S

StevenD72 via OfficeKB.com

Papou,

I think I am missing something. When I use the .characters.Text method, I
makes everything in the text box the same size and such. Can you have a look
at my code and see what I missed? I am just trying to paste the information
in the variable TotalChg if that helps.


'-----------------------------------------------------------------------------
-----
Sub Fill_Letter()

Dim ws As Worksheet
Dim ws2 As Worksheet
Set ws = Worksheets("Billing Letter")
Set ws2 = Worksheets("Billing Statement")

'Get Info from Billing Statement

Inc_Date = ws2.Cells.Range("D1").Value
Inc_No = ws2.Cells.Range("L1").Value
Inc_Addrs = ws2.Cells.Range("C8").Value
Con_Name = ws2.Cells.Range("D12").Value
Con_Comp = ws2.Cells.Range("E11").Value
Con_Addrs = ws2.Cells.Range("C13").Value
Con_City = ws2.Cells.Range("B14").Value
Con_State = ws2.Cells.Range("H14").Value
Con_Zip = ws2.Cells.Range("J14").Value
FD = ws2.Cells.Range("D2").Value
TotalChg = ws2.Cells.Range("L40").Value

'Place Header on page
ws.DrawingObjects("HeaderBox").Select
Selection.Characters.Text = "THIRD DISTRICT CHIEF'S ASSOCIATION" & Chr(10) _
& "M.A.B.A.S DIVISION 24" & Chr(10) _
& "HAZARDOUS MATERIALS RESPONSE TEAM" & Chr(10) _
& "BILLING STATEMENT"

'Place main letter on Page
ws.DrawingObjects("Textbox2").Select

Sdate = FormatDateTime(Date, vbLongDate) 'Gets Todays Date

Selection.Characters.Text = Sdate _
& Chr(10) & Chr(10) _
& Con_Name & Chr(10) & Con_Comp & Chr(10) _
& Con_Addrs & Chr(10) & Con_City & ", " _
& Con_State & " " & Con_Zip & Chr(10) & Chr(10) _
& "This statement is for services provided by the MABAS 24 Hazardous
Materials " _
& "Response Team for the following incident: " & Inc_No _
& " on " & Inc_Date & " at " & Inc_Addrs & "." _
& Chr(10) & Chr(10) _
& "The Hazardous Materials Team responded at the request of the " & FD _
& " Fire Department. The Team provided technical support. " _
& "These charges are for services provided by the MABAS 24 Hazardous
Materials " _
& "Response Team only. Other charges may be pending from municipalities
or " _
& "clean-up companies if required." & Chr(10) & Chr(10) _
& "Total charges for services provided by HazMat Response Team: " &
TotalChg _
& Chr(10) & Chr(10) _
& "See attached statement of services." _
& Chr(10) & Chr(10)

Selection.Characters.Text = Selection.Characters.Text _
& "Please remit to:" & Chr(10) & Chr(10) _
& "Third District Chief’s Association" _
& Chr(10) & "C/O Deb Hoiden" _
& Chr(10) & "Flossmoor Fire Department" _
& Chr(10) & Chr(10) _
& "Any questions, please contact me @ 708-362-0561, or email
(e-mail address removed)" _
& Chr(10) & Chr(10) _
& "Sincerely," & Chr(10) & Chr(10) & Chr(10) & Chr(10) _
& "FF/PM Scott Stegenga" & Chr(10) & "Billing Agent"

With ws.Shapes("TextBox2").TextFrame
.Characters(, Len(TotalChg)).Text = TotalChg
.Characters.Font.Bold = True
.Characters.Font.Size = 14
.Characters.Font.Name = "Arial"
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top