Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am facing problem while applying formatting(bold,italics,underline) to the paragraph written in word document. when i am reading para with range class of word object and appling font-style to the text and in that text there are brakets also like [ some text (12.5)]. so for opening square bracket and round braket loop traverse for two times each opening bracket so i want know the reason and solution

e.g.
VB
For iNum = 1 To myRange.Words.Count
     temp = aWord.Text   'aWord is a word object
Next

for openting bracket i am getting "[" text as aWord.Text for two times so pls help

Thanks

[edit]Tags only - that is VB code, not C# - OriginalGriff[/edit]
[edit]Code block included in pre tags - losmac[/edit]
Posted
Updated 9-Aug-11 8:14am
v4
Comments
Slacker007 2-Aug-11 7:30am    
Would you be able to edit this question and provide a code sample? I would love to help you on this but I need to see the code. Thanks. :)
thatraja 3-Aug-11 1:15am    
Show your code

1 solution

Simple way to achieve this is:
VB
Option Explicit

Sub GetSomeBrackets()
Dim doc As Document, par As Paragraph, rng As Range
Dim bPos As Long, ePos As Long, sText As String

Set doc = ThisDocument
For Each par In doc.Paragraphs
    sText = par.Range.Text
    bPos = InStr(1, sText, "[")
    ePos = InStr(bPos + 1, sText, "]")
    If bPos > 0 And ePos > 0 Then
        Set rng = par.Range
        rng.MoveStart Unit:=wdCharacter, Count:=bPos - 1
        rng.End = rng.Characters(Int(ePos - bPos) + 1).End
        rng.Select
        rng.Bold = True
        MsgBox rng.Text, vbInformation, Len(rng.Text)
        'MsgBox Mid(sText, bPos, ePos - bPos)
        Set rng = Nothing
    End If
Next
Set doc = Nothing
Set par = Nothing


End Sub
 
Share this answer
 
v2

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