Results 1 to 5 of 5

Thread: Replacing text in Word Doc.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Location
    North Carolina
    Posts
    102

    Replacing text in Word Doc.

    I am replacing text in a word document and it is working fine except in my 'If Then-End If' statement. I can not figure out why it isn't working, so I thought I would ask for some help. I have left out all the declarations and other code so as to not take up so much space here.
    VB Code:
    1. Set objWdApp = New Word.Application
    2.     Set objWdDoc = objWdApp.Documents.Open(FileName:="\\Taft\gis\test.doc")
    3.     Set objwdRange = objWdDoc.Content
    4.     With objwdRange.Find
    5.     .Replacement.ClearFormatting
    6.  
    7.     .Text = "lotarea"                                   'this part works great.
    8.     .Replacement.Text = strlotarea
    9.     .Execute Replace:=wdReplaceAll
    10.  
    11.    
    12.     If Text1(6).Text = "R6" Then                   'this part gives me nothing.
    13.     strlotarea = "6,000"
    14.    .Text = "lotarea"
    15.     .Replacement.Text = strlotarea
    16.     .Execute Replace:=wdReplaceAll

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Replacing text in Word Doc.

    What you want to do? I don't see any errors on your code? give us a more details. Are you getting any errors. not working means, what?
    CS

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Replacing text in Word Doc.

    What does Text1(6).text represent? Is it a text box, or is it referring to parts of the actual document text. If you're trying to get to a text box, then that isn't how Word references them when they're in a document.
    Can I suggest recording a macro to learn what the syntax is for what you're trying to do, and then stripping out all the unnecessary bits?

    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Location
    North Carolina
    Posts
    102

    Re: Replacing text in Word Doc.

    Text1(6).Text is a text box on my from. After my other code executes a code will apperar in this text box. If "R6" is displayed in the text box I want the code I posted to execute. No errors, but nother appers on my word document. Where I have the word "lotarea" on the document will usually display a given number when the code is ran, but when Text1(6).Text displays "R6", it is left blank.
    Thanks

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Location
    North Carolina
    Posts
    102

    Re: Replacing text in Word Doc.

    Can anybody look at this again and give me an idea? I am still stuck.
    Thanks.

Posting Permissions

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



Click Here to Expand Forum to Full Width