none
Finding special characters in MS-Word .doc RRS feed

  • Question

  • I would like to know how to find special charecters such as a paragraph break then write to the doc after each one? Any help would be greatly appreaciated!
    • Moved by Kee Poppy Tuesday, November 22, 2011 7:25 AM (From:Visual Basic Express Edition)
    Saturday, November 19, 2011 6:54 PM

Answers

  • I disagree Crazypennie, I think sometimes you do need to identify those characters.

     

    SOME characters can be stated using Visual Basic constants. So:

    Dim one As String = vbCr

    Will will give you a variable which represents the paragraph break character.

     

    ANY character for word interop can be stated by casting an integer. So with:

    Dim one As Char = ChrW(47)

    Dim two As Char = ChrW(13)

    Variable one will store the backlash character, because 47 is numerical version of the unicode entry for \. Variable two will hold the paragraph break character, because 13 is the unicode value for vbCr.

     

    This is some code I use to get the numerical value of characters from Word:

            Dim Sel As Selection
            Sel = Globals.ThisAddIn.Application.Selection
            Dim stringy As String = Sel.Text
            Dim chary As Char = stringy.Chars(0)
            Dim inty As Integer = AscW(chary)

            MsgBox(inty)

    It will report the numerical version of the first character of the selected text. It is important because for example,  a normal quote mark (') is what you get normally inserting text, it is Unicode 39. However by default, Word uses curly directional quotes ( ‘ and ’), which you need to know are represented by numbers 8216 and 8217 if you want to use them.  

     

    • Marked as answer by Bruce Song Monday, December 5, 2011 10:07 AM
    Tuesday, November 22, 2011 5:00 PM

All replies

  •  

    You dont need to find the characteres, You just use the existing functions

    examples , with paragraphs ...

     

            Dim oWord As New Word.Application
            Dim oDoc = oWord.Documents.Open("C:\tst\WordDocument.docx")
            oWord.Visible = True
            oDoc.Activate()
    
            'Get an array of all paragraph
            Dim AllParaghaphs = oDoc.Paragraphs
    
            'Get the range of a  paragraph 3
            Dim ContentOfParagraph3 = AllParaghaphs(3).Range
    
            'Get the text of that paragraph
            Dim TextOfParagraph3 = ContentOfParagraph3.Text
    
            'Change the text in the paragrapg
            ContentOfParagraph3.Text = "CrazyPennie" & vbCrLf
    
            'Insert the paragraph " This was writen By CrazyPennie"
            ' between the 4rd and 5th paragraph
            AllParaghaphs(4).Range.Text &= " This was writen By CrazyPennie" & vbCrLf
    

     

    Hopefully this help


    • Edited by Crazypennie Saturday, November 19, 2011 8:12 PM
    Saturday, November 19, 2011 8:06 PM
  • Hi almostAlwaysLost,

    I am going to move this thread to Word for Developers forum as it is a better place for your question.

    Have a nice day,


    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, November 22, 2011 7:24 AM
  • Can you say more about what you are trying to accomplish? 

    Are you trying to find special characters in a document or selection range? Or are you trying to position the insertion point at a given special character?  Once you locate the character what do you want to do?


    Kind Regards, Rich ... http://greatcirclelearning.com
    Tuesday, November 22, 2011 4:32 PM
  • I disagree Crazypennie, I think sometimes you do need to identify those characters.

     

    SOME characters can be stated using Visual Basic constants. So:

    Dim one As String = vbCr

    Will will give you a variable which represents the paragraph break character.

     

    ANY character for word interop can be stated by casting an integer. So with:

    Dim one As Char = ChrW(47)

    Dim two As Char = ChrW(13)

    Variable one will store the backlash character, because 47 is numerical version of the unicode entry for \. Variable two will hold the paragraph break character, because 13 is the unicode value for vbCr.

     

    This is some code I use to get the numerical value of characters from Word:

            Dim Sel As Selection
            Sel = Globals.ThisAddIn.Application.Selection
            Dim stringy As String = Sel.Text
            Dim chary As Char = stringy.Chars(0)
            Dim inty As Integer = AscW(chary)

            MsgBox(inty)

    It will report the numerical version of the first character of the selected text. It is important because for example,  a normal quote mark (') is what you get normally inserting text, it is Unicode 39. However by default, Word uses curly directional quotes ( ‘ and ’), which you need to know are represented by numbers 8216 and 8217 if you want to use them.  

     

    • Marked as answer by Bruce Song Monday, December 5, 2011 10:07 AM
    Tuesday, November 22, 2011 5:00 PM
  • thanks alot, the paragraphs thing has really put me in the correct direction. This has really helped in understanding how to programaticlly enter <html> tags,so thanks once again.
    Mario
    Monday, December 5, 2011 6:50 PM
  • I am trying to to identify characters so I can enter html tags such as color and bold text.

    any help would be greatly appreciated. I do this as a hobby so I really am not under any pressure, but it would be satisfying to succeed.

     


    Mario
    Monday, December 5, 2011 6:58 PM
  • Thanks for the info. It will come in handy as I do need to identify the start and end of each paragraph. This seems as it will be most helpful.
    Mario
    Monday, December 5, 2011 7:29 PM