MsOf03 [RESOLVED] editing word document 2003-VBForums
Results 1 to 8 of 8

Thread: [RESOLVED] editing word document 2003

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    5

    Resolved [RESOLVED] editing word document 2003

    i want to create a font converter software that convert a font to another font in my regional language...

    i have done all the hardwork...only one problem left that is
    "i m not able edit it word by word"

    plz help...

  2. #2
    Addicted Member
    Join Date
    Nov 2011
    Posts
    129

    Re: editing word document 2003

    If you want to loop through all the words in a document, use a for...each loop:

    Code:
    For Each sWord in wdDoc.Range.Words
        ' Change the font for sWord
    Next
    You can
    Code:
    Dim sWord as Word.Range
    Click "Rate This Post" if I helped you in any way.

    The best process for finding help.
    Step 1: Google it
    Step 2: Google it again
    Step 3: Google it yet again
    Step 4: Ask on a forum
    Step 5: Go to Step 1

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    5

    Question Re: editing word document 2003

    i use the following code

    Dim wrd As New Word.Application
    Dim dc As Word.Document
    Set dc = wrd.Documents.Open(pathtomyfile)


    For i = 1 To Word.ActiveDocument.Paragraphs.Count
    For Each w In Word.ActiveDocument.Paragraphs(i).Range.Words
    s = w.Text
    w.Text = convert_font(s)
    w.Font.Name = myfont
    Next w
    next i
    word.ActiveDocument.Save

    here convert_font is a function that returns a string... i want the text of each word in the document is replaced with the value return by convert_font and then set the font name to my regional language font....

    but it produce some wrong output in the document...

    plz help... i have tried everything

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,939

    Re: editing word document 2003

    if you want more help, post a sample document, to show original text and desired result, including code and function



    vb Code:
    1. For i = 1 To dc.Paragraphs.Count
    2. For Each w In dc.Paragraphs(i).Range.Words
    3. s = w.Text
    4. w.Text = convert_font(s)
    5. w.Font.Name = myfont
    6. Next w
    7. next i
    8. dc.Save
    Last edited by westconn1; Jan 5th, 2012 at 04:56 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    5

    Re: editing word document 2003

    i had already used it...it just convert the first word of the document again and again and goes to infinite loop...

    i m explaining here what i want to do...

    i have a word document which contain some text e.g

    abc defs asdrfhfs shdf dgfk
    dfjdf fgdfg fdghddf


    i want to convert the text in the document to look like..

    dfs dfgf dfgffgfg gfgf fgfg
    fgfgf fgfgg gfgfgffg


    the conversion is to be done by the function convert_font that looks like..

    Code:
    function convert_font( s as string) as string
    'some database queries
    ' and set the convert_font to legal converted string
    
    
    end function

  6. #6
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,197

    Re: editing word document 2003

    it looks as if you are trying to make a simple translator

    i am guessing because it makes no sence to pass a word to get it back unless it has changed

    and I am guessing you language requires very different shaped characters

    so...
    selecting whole document and then change font

    makes no sense to you

    are changing the whole document to a single font

    or

    are you changing a number of fonts into several different fonts


    here to talk

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,939

    Re: editing word document 2003

    i would sort of guess that the font you want to change to is a unicode type font, and you may need to use strconv to convert the returned sting to a unicode string before the unicode font can work with it
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    5

    Re: [RESOLVED] editing word document 2003

    thanks you solve my problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.