#1
|
||||
|
||||
Formatting text in VBA
Hi friends!!
Little by little with everybody's help I am starting to realize what and how to do some things in VB and what I cannot do (or at least should attempt to do Can you format a text string BEFORE it is inserted within the doc? I mean it doesn't "exist" yet. If If I have a string of text "Have a good day" and want to format it with the char style "MyCharStyle" AND THEN insert it somewhere, how would that be done? Thank you and have a good day! Susan Flamingo |
#2
|
|||
|
|||
That isn't possible because strings only contain text, not formatting. That is why the Range object contains two properties, Text, a string with no formatting, and FormattedText, which does as its name suggests.
To apply a character style you need to insert the text into the document, then apply the style. |
#3
|
|||
|
|||
As Italophile explains. No.
Why? What difference does it make if it is formatted before or after if the net result is formatted? You could use: Code:
Sub Demo() InsertStringAsFormattedText "Have a good day ", "MyCharStyle" End Sub Sub InsertStringAsFormattedText(strText, strStyle) 'A basic Word Macro coded by Gregory K. Maxey Dim oRng As Range Set oRng = Selection.Range oRng.Text = strText oRng.Style = strStyle lbl_Exit: Exit Sub End Sub |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Text Wrapping Without a Table or Text-box (Formatting Assistance) | COWNoah | Word | 8 | 08-08-2023 02:55 PM |
Replacing a comment with underline or other formatting (or adding that formatting to commented text) | paulkaye | Word | 4 | 05-16-2016 05:38 AM |
The Logic Behind Apply Formatting of Surrounding Text in Reveal Formatting Pane | Instructor Mark | Word | 4 | 04-06-2016 01:32 PM |
text formatting | kjared7 | PowerPoint | 1 | 12-26-2014 07:42 PM |
Formatting- Apply changes to highlighted text results in same change to other text | sential | Word | 6 | 01-10-2014 03:22 PM |