Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bold text 2

Status
Not open for further replies.

kalle82

Technical User
Apr 2, 2009
163
SE
I have this code snippet.

" och ska skickas till:" & _
vbCrLf & vbCrLf & "Kassaregisterfunktionen" & _
vbCrLf & "Skattekontor 2 Göteborg" & _
vbCrLf & "Box 28 25" & vbCrLf & _
"403 20 Göteborg" & vbCrLf & vbCrLf & _
"Ange handläggarens namn och referensnummer i svaret." & _ vbCrLf & vbCrLf & vbCrLf


I want to make "Ange handläggarens namn och referensnummer i svaret." text bold.

The only thing ive learnt is the wdtoggle but as im in a string(i think it is) i can´t use it.

How do i do to make the text bold?

thanks

//Carl
 



Carl,

I do not believe that you can format part of text in a formula.

You could, however, split the formula into three separate parts and apply formatting to any of the results.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
This is a string i use to update my bookmarks instead of all the "selection.type" things i had before.

Im using a bookmarks to update specific pieces based on optionbuttons.

Ill try with the wdtoggle.

Ill post some code here tomorrow, Im really stuck on this one.. Its crazy with all IF´s and bookmark updates...



 
Here is how it goes when i update my bookmarks.

Kinda crzy way of doing it.. Still i need the
"Ange handläggarens namn och referensnummer i svaret."
to be bold.

UpdateBookmark "bokmark3", " och ska skickas till:" & _
vbCrLf & vbCrLf & "Kassaregisterfunktionen" & _
vbCrLf & "Skattekontor 2 Göteborg" & _
vbCrLf & "Box 28 25" & vbCrLf & _
"403 20 Göteborg" & vbCrLf & vbCrLf & _
"Ange handläggarens namn och referensnummer i svaret." & _ vbCrLf & vbCrLf & vbCrLf
 
Skip...you Excel maniac...it is for Word.

kalle82, as it is, no, you can not pass part of a string as bold. A string has no real format. It is a string.

I would seriously question having all that different text (including so many "empty" paragraphs) in ONE bookmark.

First of all, properly done with styles, you should have NO "empty" paragraphs - your vbCrLf, or in your original thread, the Selection.TypeParagraph - at all. Using "empty" paragraphs to create space between paragraphs is a very bad use of Word.

However, since you are, in fact, doing that, it IS possible to make part of the text - after you have put it in the bookmark - bold.
Code:
Option Explicit

Sub MakePartBold()
Dim r As Range
Dim strBoldMe As String

strBoldMe = "Ange handläggarens namn och " & _
   "referensnummer i svaret."
   
Set r = ActiveDocument.Bookmarks("bokmark3").Range

With r.Find
   .ClearFormatting
   .Replacement.Font.Bold = True
   .Execute Findtext:=strBoldMe, _
      Forward:=False, Replace:=True
End With
End Sub
This goes through the contents of the bookmark and makes the string strBoldMe - set as "Ange handläggarens namn och referensnummer i svaret." - bold.

You could do this separate, after you put the text in of course; OR you could adjust your bookmark filling procedure to accept a third parameter (the string to be bolded). If you went that route, you would have to action the bolding AFTER you have:

1. put the text into the bookmark
2. created the bookmark again

BTW: it would be cleaner to pass the long string you have to your UpdateBookmark procedure as a string variable, rather than a string literal.
Code:
Dim strIn As String
strIn = " och ska skickas till:" & _
   vbCrLf & vbCrLf & "Kassaregisterfunktionen" & _
   vbCrLf & "Skattekontor 2 Göteborg" & _
   vbCrLf & "Box 28 25" & vbCrLf & _
   "403 20 Göteborg" & vbCrLf & vbCrLf & _
   "Ange handläggarens namn och referensnummer i svaret." & _ vbCrLf & vbCrLf & vbCrLf

Call UpdateBookmark ("bokmark3", strIn)

If you wanted to pass in the string part to be bolded, you need to change the UpdateBook procedure itself.

Sub UpdateBookmark (strBM_Name As String, _
strText As String, _
strBoldThis As String)

Then you could do:
Code:
Dim strIn As String
Dim strBoldThis As String

strIn = " och ska skickas till:" & _
   vbCrLf & vbCrLf & "Kassaregisterfunktionen" & _
   vbCrLf & "Skattekontor 2 Göteborg" & _
   vbCrLf & "Box 28 25" & vbCrLf & _
   "403 20 Göteborg" & vbCrLf & vbCrLf & _
   "Ange handläggarens namn och referensnummer i svaret." & _ vbCrLf & vbCrLf & vbCrLf

strBoldThis = "Ange handläggarens namn och referensnummer i svaret."

Call UpdateBookmark ("bokmark3", strIn, strBoldThis)


Gerry
 




I am, without a doubt, Word challenged, Word devoid and Word inept.

I defer to the last word in "Word."

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks alot, for taking the time to explain it in such a descriptive way!!!

Cheers

//Carl
 


I second that emotion.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thank...ummmm, reality...for Skip! You have made me laugh so many times. I really do appreciate you. I am having a very bad morning (I went outside last night and startled a racoon right outside my door, and it reared up and bit my hand. I think I perhaps should leave work and go seek some medical attention as the wounds seem to be already infected...actually...I feel kind of funny....), and having a laugh is wonderful.

Lassie...what is it girl? Is there something wrong with Timmy?

Ooooooooo, look at all the pretty colors.

Gerry
 


Gerry, take care of that bite, please!!! I know you're a swell guy, but not THAT swell!

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
kalle82, just to clarify about changing your UpdateBook procedure, in order to pass in a part of the string to be bold:
Code:
Sub UpdateBookmark2(bokmark1 As String, _
    TextToUse As String, _
    TextToBold As String)

    Dim BMRange As Range
    Set BMRange = ActiveDocument.Bookmarks(bokmark1).Range
    BMRange.Text = TextToUse
    ActiveDocument.Bookmarks.Add bokmark1, BMRange
[COLOR=red]' RESET the range object!
' this is very important[/color red]
    Set BMRange = ActiveDocument.Bookmarks(bokmark1).Range
[COLOR=red]'  now you can action the part to be bolded[/color red]
With BMRange.Find
   .ClearFormatting
   .Replacement.Font.Bold = True
   .Execute Findtext:=TextToBold, _
      Forward:=False, Replace:=True
End With
End Sub
With the assumption that TextToBold is, in fact, in the string variable TextToUse. If it is not, obviously nothing will happen.

Gerry
 
adlhal ajdhlhw47624pjaeehj a;dj jaj;; rkal asjk;aSI[1'ADJK' asdgagskg adl;wpjgs

jad;a0syrjalpanzgsdfql sfjjk sdfj s;'e'etjwl

Gerry
 



Geez Gerry, that's painful to read!

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
<groan>...it was even worse to type</groan>

I am on a "mission critical" conference call - on Mute and still TT-ing though! - and I am finding myself, when I do say anything, to be speaking gibberish...or maybe in tongues.

Yeah...that's the ticket. I have seen the light and I am now Pentecostal. I have this intense desire to writhe on the floor with snakes. I like snakes, although not when they startle me. So smooth and sexy.

I think I am rapidly getting worse; it feels like I am burning up. My hand has swollen up rather startlingly.





OK, that's it. Mission critical or not, screw 'em...I am outta here.....geez, I think I am going to throw up.




Sorry, I know...too much information.

Later, 'gators.

Timmy?









Mom?

Gerry
 



Hope you retain your consciousness, stream of.

Timmy is right here! Just relax

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top