Strange Word Late Binding Problem (1 Viewer)

Pleasure

Registered User.
Local time
Today, 22:56
Joined
Jul 26, 2005
Messages
44
Hello my friends.

I have the following problem.

I have created a function that does a "find and replace" of a string to another string. I used to have enabled the ms word reference but changed that to late bind.

So, after I have changed the code, everything SEEMS to work fine, without any error messages. But unfortunately, nothing happens. The word file is opened by the function and saved as what I want, without the string changes.

When I enable the word reference again, with the same "late binde" code, I get results (find and replace). Without the reference, no error message as also no results.

Do you have anything in mind ? This is very strange.

I use the following module:

Code:
' Some general declarations
Option Compare Database

    Public APWORD As Object
    Public doc As Object

' The change function

Public Function letschangewordfiles(sourcefile As String, destinfile As String, fro_m As String, T_o As String)

    Set APWORD = CreateObject("Word.Application")
    APWORD.Visible = False
    Set doc = APWORD.Documents.Add(sourcefile)
    doc.Select


'find and replace in the body of the document
  With APWORD.Selection.Find
    .Text =  fro_m
    .Replacement.ClearFormatting
    .Replacement.Text = T_o
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = True
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
  End With
   APWORD.Selection.Find.Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue

'find and replace in the header-footer of the document
     Dim HeaderFooter As Object
            For Each HeaderFooter In APWORD.ActiveDocument.StoryRanges
                With HeaderFooter.Find
                    .Text =  fro_m
                    .Replacement.Text = T_o
                    .Wrap = wdFindContinue
                    .Format = False
                    .Forward = True
                    .MatchCase = True
                    .MatchWholeWord = True
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                End With
            HeaderFooter.Find.Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
            Next


'find and replace inside the shapes of the document
For Each s In doc.Shapes
On Error Resume Next
With s.TextFrame.TextRange.Find
    .Text =  fro_m
    .Replacement.Text = T_o
    .Wrap = wdFindContinue
    .Format = False
    .Forward = True
    .MatchCase = True
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue

    End With
Next


        doc.SaveAs (destinfile)
        doc.Close False

End Function

So. Without reference to word I get no error messages, the code runs but nothing is changed inside a word file. With the reference enabled (even if it is no needed), I have the results that I want.

Thanks in advance my friends and sorry about my lousy English. Perhaps I should have tried to express my self in Greek lol
 

Users who are viewing this thread

Top Bottom