How can I bold a portion of a string which I have stored in a variable?

UforDinner

New Member
Joined
Apr 26, 2016
Messages
1
How can I bold a portion of a string which I have stored in a variable?

Hi All, First, thank you for any help in advance. I have read on this forum dozens of times in search of answers to my questions and everyone has always been so helpful. After doing exhaustive searches on google and here, I cannot seem to figure this out or if it is even possible.

I am working on a small spreadsheet for my work... in short... it has a couple of cells which are filled through data validation drop downs and it has a couple of radio buttons. The user selects from the drop downs and picks yes or no on a couple of radio button questions. I have created a "Copy to Letter" button on the screen which I have bound to a subroutine.

In essence, based on the user's selections, the "Copy to letter" button will create a formal letter (which we send to customers) and it uses all the wording and different paragraphs I desire based on the drop-downs or buttons the user selected. The entire letter is stored within a string variable and then is placed into the clipboard... so that my user can access another system we have and click paste to put the standardized wording/formatting into the letter system.

Everything works perfectly fine from a function standpoint... Okay, here is the problem, I really need a few spots of the letter to be BOLD in font. The location of the bold words/sentences does change based on the drop downs and radio buttons as the letter contents change with these selections.

I have tried using the Characters function with InStr to locate the characters I want to bold and then bold them... but I always get an error.

Here is an example… imagine txt_all is a much much longer string which is a one page letter. For example, I want to bold just the word “love”…

Code:
txt_all = "Thank you for calling our business.  We love all customers!"
 
txt_all.Characters(InStr(txt_all, “love”), 4).Font.Bold = True
 
'Set object's text equal above string variable
  obj.SetText txt_all
 
'Place DataObject's text into the Clipboard
  obj.PutInClipboard

One thing I have found which is unique with my application compared to others who give examples of Characters function is that my string is stored in a variable and not in a cell or a range of cells... the variable is manipulated based on the user options, it is stored in the clipboard... then the user would go from excel to our other system and simply paste the result and send their letter. Hope all that makes sense.

Thanks so much for any help!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I'm sorry but you can't bold a portion of a string variable, all it can hold is text.
 
Upvote 0

Forum statistics

Threads
1,215,779
Messages
6,126,848
Members
449,343
Latest member
DEWS2031

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top