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”…
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!
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!