Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a richtextbox and I want to save it's text to a word file.

But after I save the text in the word when I open that word file I saved I see for example if I bold word "A",now it's not Bold!

How I can do that?

Thanks
Posted
Comments
Nelek 9-May-14 3:35am    
One possibility could be to check first the attributes and then save them with the text, so that when you read the text another time, you can set the attributes back as well.

1 solution

In the same way as you do it manually: by selecting range (single character or word or paragraph or set of characters, words or paragraphs) and pushing Bold command from ribbon.

Have a look here:
How to: Programmatically Define and Select Ranges in Documents[^]
How to: Programmatically Format Text in Documents[^]
Range.Bold[^] property ;)

Note: if you save a document as a text, you'll lose formatting.

Tip: Run MS Word application. When new document is created, type some text, then start recording macro. Select text and bold it. Stop recording. Push ALT+F11 to switch to CodePane.

Here is what i get:
VB
Sub Macro1()
'
' Macro1 Macro
'
'
    Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
    Selection.MoveLeft Unit:=wdCharacter, Count:=7, Extend:=wdExtend
    Selection.Font.Bold = wdToggle
End Sub
 
Share this answer
 
v3
Comments
Pouya Mozafar 9-May-14 3:53am    
Can you give me a code example?

A simple code example?
Maciej Los 9-May-14 3:55am    
Follow the first and second link (at the bottom of article you'll find it).
Pouya Mozafar 11-May-14 10:45am    
"word.range" this code is not work and gives me an error.
Maciej Los 11-May-14 10:47am    
Did you properly set a reference to Word.Interop?
Pouya Mozafar 11-May-14 10:50am    
No,

How can I do that?

Please give me a complete code not a line.

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900