Results 1 to 4 of 4

Thread: Replacement Text not being replaced.

  1. #1

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

    Replacement Text not being replaced.

    I am using a form in vb that has a print command button. This pulls up a word doc with text from my form's textboxes. It works fine except in this 'if then' instance. I don't understand why it doens't work. When I place a breakpoint in the code and walk through it, I can see with the text tool tip box that my variable has the right text in, but it will not appear on the word document. It is just blank. Can anybody help?
    Code:
    strlotarea = Text1(12).Text 
    Set objWdApp = New Word.Application 
    Set objWdDoc = objWdApp.Documents.Open(FileName:="\\Taft\gis\test.doc") 
    Set objwdRange = objWdDoc.Content 
    With objwdRange.Find 
      .Replacement.ClearFormatting 
      .Text = "lotarea" 
      .Replacement.Text = strlotarea        ‘works fine 
       .Execute Replace:=wdReplaceAll 
            If Text1(6).Text = "R6" Then 
            strlotarea = "6,000" 
            objwdRange.Find.Text = "lotarea" 
            objwdRange.Find.Replacement.Text = strlotarea    ‘left blank on doc. 
            objwdRange.Find.Execute Replace:=wdReplaceAll 
            End If

  2. #2
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Re: Replacement Text not being replaced.

    Only a guess but do you need some kind of document refresh after doing that ?

  3. #3

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

    Re: Replacement Text not being replaced.

    There isn't a refresh event/method for the objwdRange. How else can you write it so that it would refresh?

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

    Re: Replacement Text not being replaced.

    Hi,

    Quote Originally Posted by kpearson
    Code:
    With objwdRange.Find 
      .Replacement.ClearFormatting 
      .Text = "lotarea" 
      .Replacement.Text = strlotarea        ‘works fine 
       .Execute Replace:=wdReplaceAll
    Here you replaced all the text "lotarea". Now there will be no text "lotarea" in the document.
    Quote Originally Posted by kpearson
    Code:
            If Text1(6).Text = "R6" Then 
            strlotarea = "6,000" 
            objwdRange.Find.Text = "lotarea" 
            objwdRange.Find.Replacement.Text = strlotarea    ‘left blank on doc. 
            objwdRange.Find.Execute Replace:=wdReplaceAll 
            End If
    How you will find & replace the same text here again.
    CS

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