Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: find and replace not working in the header footer


Message #1 by <odempsey@b...> on Mon, 18 Nov 2002 23:24:59 -0000
Hi folks
I am using Access VBA to do a find and replace in a Word document.  However it doesn't replace the
text in the header / footer.  Here is the code that I was using.

    Set m_objWord = New Word.Application

        Set m_objDoc = m_objWord.Documents.Add(m_strTEMPLATEDIR & m_strTHOMASPROPOSALTEMPLATE)


With m_objWord.Selection.Find
    .ClearFormatting
    .Text = "[....................................]"
    .Replacement.ClearFormatting
    .Replacement.Text = "company Name here"
         .MatchCase = True
     .MatchWholeWord = True
     .MatchWildcards = False
    .Execute Replace:=wdReplaceAll, Forward:=True, _
        Wrap:=wdFindContinue
End With

According to Microsoft's help files, I need to use the StoryRanges collection to access the whole
document and this is what I tried below but I am getting a mismatch error.  I first tried using
objWord.StoryRanges but that doesn't seem to work so I used ActiveDocument.StoryRanges instead

Dim mystoryrange As Range
For Each mystoryrange In ActiveDocument.StoryRanges
    With mystoryrange.Selection.Find
    .ClearFormatting
    .Text = "[....................................]"
    .Replacement.ClearFormatting
    .Replacement.Text = "company Name here"
         .MatchCase = True
     .MatchWholeWord = True
     .MatchWildcards = False
    .Execute Replace:=wdReplaceAll, Forward:=True, _
        Wrap:=wdFindContinue
End With
    While Not (mystoryrange.NextStoryRange Is Nothing)
        With mystoryrange.Selection.Find
    .ClearFormatting
    .Text = "[....................................]"
    .Replacement.ClearFormatting
    .Replacement.Text = "company Name here"
         .MatchCase = True
     .MatchWholeWord = True
     .MatchWildcards = False
    .Execute Replace:=wdReplaceAll, Forward:=True, _
        Wrap:=wdFindContinue
End With
    Wend
Next mystoryrange

But as I say, this is giving a type mismatch error.  Has anybody got an idea how to solve this
problem?


Many Thanks
Oliver Dempsey



Message #2 by "Leo Scott" <leoscott@c...> on Mon, 18 Nov 2002 22:43:23 -0800
You might get better results asking this question on the Word_VBA forum.  I
did look at it briefly and it seems that to look in the headers with VBA you
have to loop through the Document.Sections collection and then loop through
the Section.Headers collection to search all the Headers since they are part
of a section.  If you want to find/replace in Footers they are part of a
section also.  I'm not much with Word VBA but this is what I saw.  I wrote a
quick test program and it did find text in a header with this approach.

|-----Original Message-----
|From: odempsey@b... [mailto:odempsey@b...]
|Sent: Monday, November 18, 2002 3:25 PM
|To: Access
|Subject: [access] find and replace not working in the header footer
|
|
|Hi folks
|I am using Access VBA to do a find and replace in a Word document.
| However it doesn't replace the
|text in the header / footer.  Here is the code that I was using.
|
|    Set m_objWord = New Word.Application
|
|        Set m_objDoc = m_objWord.Documents.Add(m_strTEMPLATEDIR &
|m_strTHOMASPROPOSALTEMPLATE)
|
|
|With m_objWord.Selection.Find
|    .ClearFormatting
|    .Text = "[....................................]"
|    .Replacement.ClearFormatting
|    .Replacement.Text = "company Name here"
|         .MatchCase = True
|     .MatchWholeWord = True
|     .MatchWildcards = False
|    .Execute Replace:=wdReplaceAll, Forward:=True, _
|        Wrap:=wdFindContinue
|End With
|
|According to Microsoft's help files, I need to use the StoryRanges
|collection to access the whole
|document and this is what I tried below but I am getting a
|mismatch error.  I first tried using
|objWord.StoryRanges but that doesn't seem to work so I used
|ActiveDocument.StoryRanges instead
|
|Dim mystoryrange As Range
|For Each mystoryrange In ActiveDocument.StoryRanges
|    With mystoryrange.Selection.Find
|    .ClearFormatting
|    .Text = "[....................................]"
|    .Replacement.ClearFormatting
|    .Replacement.Text = "company Name here"
|         .MatchCase = True
|     .MatchWholeWord = True
|     .MatchWildcards = False
|    .Execute Replace:=wdReplaceAll, Forward:=True, _
|        Wrap:=wdFindContinue
|End With
|    While Not (mystoryrange.NextStoryRange Is Nothing)
|        With mystoryrange.Selection.Find
|    .ClearFormatting
|    .Text = "[....................................]"
|    .Replacement.ClearFormatting
|    .Replacement.Text = "company Name here"
|         .MatchCase = True
|     .MatchWholeWord = True
|     .MatchWildcards = False
|    .Execute Replace:=wdReplaceAll, Forward:=True, _
|        Wrap:=wdFindContinue
|End With
|    Wend
|Next mystoryrange
|
|But as I say, this is giving a type mismatch error.  Has anybody
|got an idea how to solve this
|problem?
|
|
|Many Thanks
|Oliver Dempsey
|
|
|
|

Message #3 by <odempsey@b...> on Tue, 19 Nov 2002 10:58:59 -0000
Hi Leo
thanks for your reply.  Can you show me the quick test program that you did to find text in a header
because I haven't been successful in doing it yet.

I will post the query on the word vba forum as well although there seems to very little activity on
it.

Many Thanks
Oliver Dempsey


----- Original Message -----
From: "Leo Scott" <leoscott@c...>
To: "Access" <access@p...>
Sent: Tuesday, November 19, 2002 6:43 AM
Subject: [access] RE: find and replace not working in the header footer


> You might get better results asking this question on the Word_VBA forum.  I
> did look at it briefly and it seems that to look in the headers with VBA you
> have to loop through the Document.Sections collection and then loop through
> the Section.Headers collection to search all the Headers since they are part
> of a section.  If you want to find/replace in Footers they are part of a
> section also.  I'm not much with Word VBA but this is what I saw.  I wrote a
> quick test program and it did find text in a header with this approach.
>
> |-----Original Message-----
> |From: odempsey@b... [mailto:odempsey@b...]
> |Sent: Monday, November 18, 2002 3:25 PM
> |To: Access
> |Subject: [access] find and replace not working in the header footer
> |
> |
> |Hi folks
> |I am using Access VBA to do a find and replace in a Word document.
> | However it doesn't replace the
> |text in the header / footer.  Here is the code that I was using.
> |
> |    Set m_objWord = New Word.Application
> |
> |        Set m_objDoc = m_objWord.Documents.Add(m_strTEMPLATEDIR &
> |m_strTHOMASPROPOSALTEMPLATE)
> |
> |
> |With m_objWord.Selection.Find
> |    .ClearFormatting
> |    .Text = "[....................................]"
> |    .Replacement.ClearFormatting
> |    .Replacement.Text = "company Name here"
> |         .MatchCase = True
> |     .MatchWholeWord = True
> |     .MatchWildcards = False
> |    .Execute Replace:=wdReplaceAll, Forward:=True, _
> |        Wrap:=wdFindContinue
> |End With
> |
> |According to Microsoft's help files, I need to use the StoryRanges
> |collection to access the whole
> |document and this is what I tried below but I am getting a
> |mismatch error.  I first tried using
> |objWord.StoryRanges but that doesn't seem to work so I used
> |ActiveDocument.StoryRanges instead
> |
> |Dim mystoryrange As Range
> |For Each mystoryrange In ActiveDocument.StoryRanges
> |    With mystoryrange.Selection.Find
> |    .ClearFormatting
> |    .Text = "[....................................]"
> |    .Replacement.ClearFormatting
> |    .Replacement.Text = "company Name here"
> |         .MatchCase = True
> |     .MatchWholeWord = True
> |     .MatchWildcards = False
> |    .Execute Replace:=wdReplaceAll, Forward:=True, _
> |        Wrap:=wdFindContinue
> |End With
> |    While Not (mystoryrange.NextStoryRange Is Nothing)
> |        With mystoryrange.Selection.Find
> |    .ClearFormatting
> |    .Text = "[....................................]"
> |    .Replacement.ClearFormatting
> |    .Replacement.Text = "company Name here"
> |         .MatchCase = True
> |     .MatchWholeWord = True
> |     .MatchWildcards = False
> |    .Execute Replace:=wdReplaceAll, Forward:=True, _
> |        Wrap:=wdFindContinue
> |End With
> |    Wend
> |Next mystoryrange
> |
> |But as I say, this is giving a type mismatch error.  Has anybody
> |got an idea how to solve this
> |problem?
> |
> |
> |Many Thanks
> |Oliver Dempsey
> |
> |
> |
> |
>
>
>

Message #4 by "Leo Scott" <leoscott@c...> on Tue, 19 Nov 2002 08:15:57 -0800
Public Sub SearchWholeDocument()
   Dim sec As Section
   Dim HF As HeaderFooter
   Dim blnFound As Boolean
   Dim strValue As String
   Dim rng As Range
   
   strValue = "something"
   blnFound = False
   With ActiveDocument
      If Not FindText(.Content, strValue) Then
         For Each sec In .Sections
            For Each HF In sec.Headers
               Set rng = HF.Range
               rng.WholeStory
               If FindText(rng, strValue) Then
                  blnFound = True
                  Exit For
               End If
            Next
         If blnFound Then
            Exit For
         End If
         Next
      Else
         blnFound = True
      End If
   End With
Debug.Print blnFound
End Sub

Private Function FindText(ByVal rng As Range, _
                          ByVal Value As String) As Boolean
   FindText = False
   With rng.Find
      .ClearFormatting
      .Text = Value
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Execute
      If .Found Then FindText = True
   End With
End Function

|-----Original Message-----
|From: odempsey@b... [mailto:odempsey@b...]
|Sent: Tuesday, November 19, 2002 2:59 AM
|To: Access
|Subject: [access] RE: find and replace not working in the header footer
|
|
|Hi Leo
|thanks for your reply.  Can you show me the quick test program 
|that you did to find text in a header
|because I haven't been successful in doing it yet.
|
|I will post the query on the word vba forum as well although there 
|seems to very little activity on
|it.
|
|Many Thanks
|Oliver Dempsey

Message #5 by <odempsey@b...> on Tue, 19 Nov 2002 21:56:30 -0000
Hi Leo
this is turning out to be a complicated issue, I tried that piece of code and I got the following
error with regard to
For Each HF In sec.Headers

compile error
Method or Data Member not found

It is referring to .Headers

What does this mean?

thanks so much for your help


Kind Regards
Oliver Dempsey



----- Original Message -----
From: "Leo Scott" <leoscott@c...>
To: "Access" <access@p...>
Sent: Tuesday, November 19, 2002 4:15 PM
Subject: [access] RE: find and replace not working in the header footer


> Public Sub SearchWholeDocument()
>    Dim sec As Section
>    Dim HF As HeaderFooter
>    Dim blnFound As Boolean
>    Dim strValue As String
>    Dim rng As Range
>
>    strValue = "something"
>    blnFound = False
>    With ActiveDocument
>       If Not FindText(.Content, strValue) Then
>          For Each sec In .Sections
>             For Each HF In sec.Headers
>                Set rng = HF.Range
>                rng.WholeStory
>                If FindText(rng, strValue) Then
>                   blnFound = True
>                   Exit For
>                End If
>             Next
>          If blnFound Then
>             Exit For
>          End If
>          Next
>       Else
>          blnFound = True
>       End If
>    End With
> Debug.Print blnFound
> End Sub
>
> Private Function FindText(ByVal rng As Range, _
>                           ByVal Value As String) As Boolean
>    FindText = False
>    With rng.Find
>       .ClearFormatting
>       .Text = Value
>       .Replacement.Text = ""
>       .Forward = True
>       .Wrap = wdFindContinue
>       .Format = False
>       .MatchCase = False
>       .MatchWholeWord = False
>       .MatchWildcards = False
>       .MatchSoundsLike = False
>       .MatchAllWordForms = False
>       .Execute
>       If .Found Then FindText = True
>    End With
> End Function
>
> |-----Original Message-----
> |From: odempsey@b... [mailto:odempsey@b...]
> |Sent: Tuesday, November 19, 2002 2:59 AM
> |To: Access
> |Subject: [access] RE: find and replace not working in the header footer
> |
> |
> |Hi Leo
> |thanks for your reply.  Can you show me the quick test program
> |that you did to find text in a header
> |because I haven't been successful in doing it yet.
> |
> |I will post the query on the word vba forum as well although there
> |seems to very little activity on
> |it.
> |
> |Many Thanks
> |Oliver Dempsey
>
>
>

Message #6 by "Leo Scott" <leoscott@c...> on Wed, 20 Nov 2002 00:21:45 -0800
That code was written and run in Word just as a test/demo of how to do it.
To run it from Access you will have to set a reference to the Word library
and prefix the properties and methods with a word application object
reference.  I assumed you had already knew you needed to do that since you
seemed to be accessing Word documents from Access in your initial question.

|-----Original Message-----
|From: odempsey@b... [mailto:odempsey@b...]
|Sent: Tuesday, November 19, 2002 1:57 PM
|To: Access
|Subject: [access] RE: find and replace not working in the header footer
|
|
|Hi Leo
|this is turning out to be a complicated issue, I tried that piece
|of code and I got the following
|error with regard to
|For Each HF In sec.Headers
|
|compile error
|Method or Data Member not found
|
|It is referring to .Headers
|
|What does this mean?
|
|thanks so much for your help
|
|
|Kind Regards
|Oliver Dempsey
|
|
|
|----- Original Message -----
|From: "Leo Scott" <leoscott@c...>
|To: "Access" <access@p...>
|Sent: Tuesday, November 19, 2002 4:15 PM
|Subject: [access] RE: find and replace not working in the header footer
|
|
|> Public Sub SearchWholeDocument()
|>    Dim sec As Section
|>    Dim HF As HeaderFooter
|>    Dim blnFound As Boolean
|>    Dim strValue As String
|>    Dim rng As Range
|>
|>    strValue = "something"
|>    blnFound = False
|>    With ActiveDocument
|>       If Not FindText(.Content, strValue) Then
|>          For Each sec In .Sections
|>             For Each HF In sec.Headers
|>                Set rng = HF.Range
|>                rng.WholeStory
|>                If FindText(rng, strValue) Then
|>                   blnFound = True
|>                   Exit For
|>                End If
|>             Next
|>          If blnFound Then
|>             Exit For
|>          End If
|>          Next
|>       Else
|>          blnFound = True
|>       End If
|>    End With
|> Debug.Print blnFound
|> End Sub
|>
|> Private Function FindText(ByVal rng As Range, _
|>                           ByVal Value As String) As Boolean
|>    FindText = False
|>    With rng.Find
|>       .ClearFormatting
|>       .Text = Value
|>       .Replacement.Text = ""
|>       .Forward = True
|>       .Wrap = wdFindContinue
|>       .Format = False
|>       .MatchCase = False
|>       .MatchWholeWord = False
|>       .MatchWildcards = False
|>       .MatchSoundsLike = False
|>       .MatchAllWordForms = False
|>       .Execute
|>       If .Found Then FindText = True
|>    End With
|> End Function
|>
|> |-----Original Message-----
|> |From: odempsey@b... [mailto:odempsey@b...]
|> |Sent: Tuesday, November 19, 2002 2:59 AM
|> |To: Access
|> |Subject: [access] RE: find and replace not working in the header footer
|> |
|> |
|> |Hi Leo
|> |thanks for your reply.  Can you show me the quick test program
|> |that you did to find text in a header
|> |because I haven't been successful in doing it yet.
|> |
|> |I will post the query on the word vba forum as well although there
|> |seems to very little activity on
|> |it.
|> |
|> |Many Thanks
|> |Oliver Dempsey
|>
|>
|>
|
|
|

Message #7 by <odempsey@b...> on Wed, 20 Nov 2002 12:22:24 -0000
Hi Leo
yes, I am pretty new to automation but I was successfully acheiving it as follows:

    Set m_objWord = New Word.Application

        Set m_objDoc = m_objWord.Documents.Add(m_strTEMPLATEDIR & m_strTHOMASPROPOSALTEMPLATE)

inserting bookmarks, saving and printing etc.

I thought it should be just a matter of changing your line 'With ActiveDocument'  to 
'With m_objWord.ActiveDocument'

but that doesn't seem to be the case.

Any ideas?



Kind Regards
Oliver Dempsey
00353 (0)502 26263
00353 (0)86 8219430

----- Original Message ----- 
From: "Leo Scott" <leoscott@c...>
To: "Access" <access@p...>
Sent: Wednesday, November 20, 2002 8:21 AM
Subject: [access] RE: find and replace not working in the header footer


> That code was written and run in Word just as a test/demo of how to do it.
> To run it from Access you will have to set a reference to the Word library
> and prefix the properties and methods with a word application object
> reference.  I assumed you had already knew you needed to do that since you
> seemed to be accessing Word documents from Access in your initial question.
> 
> |-----Original Message-----
> |From: odempsey@b... [mailto:odempsey@b...]
> |Sent: Tuesday, November 19, 2002 1:57 PM
> |To: Access
> |Subject: [access] RE: find and replace not working in the header footer
> |
> |
> |Hi Leo
> |this is turning out to be a complicated issue, I tried that piece
> |of code and I got the following
> |error with regard to
> |For Each HF In sec.Headers
> |
> |compile error
> |Method or Data Member not found
> |
> |It is referring to .Headers
> |
> |What does this mean?
> |
> |thanks so much for your help
> |
> |
> |Kind Regards
> |Oliver Dempsey
> |
> |
> |
> |----- Original Message -----
> |From: "Leo Scott" <leoscott@c...>
> |To: "Access" <access@p...>
> |Sent: Tuesday, November 19, 2002 4:15 PM
> |Subject: [access] RE: find and replace not working in the header footer
> |
> |
> |> Public Sub SearchWholeDocument()
> |>    Dim sec As Section
> |>    Dim HF As HeaderFooter
> |>    Dim blnFound As Boolean
> |>    Dim strValue As String
> |>    Dim rng As Range
> |>
> |>    strValue = "something"
> |>    blnFound = False
> |>    With ActiveDocument
> |>       If Not FindText(.Content, strValue) Then
> |>          For Each sec In .Sections
> |>             For Each HF In sec.Headers
> |>                Set rng = HF.Range
> |>                rng.WholeStory
> |>                If FindText(rng, strValue) Then
> |>                   blnFound = True
> |>                   Exit For
> |>                End If
> |>             Next
> |>          If blnFound Then
> |>             Exit For
> |>          End If
> |>          Next
> |>       Else
> |>          blnFound = True
> |>       End If
> |>    End With
> |> Debug.Print blnFound
> |> End Sub
> |>
> |> Private Function FindText(ByVal rng As Range, _
> |>                           ByVal Value As String) As Boolean
> |>    FindText = False
> |>    With rng.Find
> |>       .ClearFormatting
> |>       .Text = Value
> |>       .Replacement.Text = ""
> |>       .Forward = True
> |>       .Wrap = wdFindContinue
> |>       .Format = False
> |>       .MatchCase = False
> |>       .MatchWholeWord = False
> |>       .MatchWildcards = False
> |>       .MatchSoundsLike = False
> |>       .MatchAllWordForms = False
> |>       .Execute
> |>       If .Found Then FindText = True
> |>    End With
> |> End Function
> |>
> |> |-----Original Message-----
> |> |From: odempsey@b... [mailto:odempsey@b...]
> |> |Sent: Tuesday, November 19, 2002 2:59 AM
> |> |To: Access
> |> |Subject: [access] RE: find and replace not working in the header footer
> |> |
> |> |
> |> |Hi Leo
> |> |thanks for your reply.  Can you show me the quick test program
> |> |that you did to find text in a header
> |> |because I haven't been successful in doing it yet.
> |> |
> |> |I will post the query on the word vba forum as well although there
> |> |seems to very little activity on
> |> |it.
> |> |
> |> |Many Thanks
> |> |Oliver Dempsey
> |>
> |>
> |>
> |
> |
> |
> 
> 
> 

Message #8 by "Leo Scott" <leoscott@c...> on Wed, 20 Nov 2002 08:54:26 -0800
I won't have time until this weekend but then I will set up a trial run from
Access and see what I can come up with for you.

|-----Original Message-----
|From: odempsey@b... [mailto:odempsey@b...]
|Sent: Wednesday, November 20, 2002 4:22 AM
|To: Access
|Subject: [access] RE: find and replace not working in the header footer
|
|
|Hi Leo
|yes, I am pretty new to automation but I was successfully
|acheiving it as follows:
|
|    Set m_objWord = New Word.Application
|
|        Set m_objDoc = m_objWord.Documents.Add(m_strTEMPLATEDIR &
|m_strTHOMASPROPOSALTEMPLATE)
|
|inserting bookmarks, saving and printing etc.
|
|I thought it should be just a matter of changing your line 'With
|ActiveDocument'  to
|'With m_objWord.ActiveDocument'
|
|but that doesn't seem to be the case.
|
|Any ideas?
|
|
|
|Kind Regards
|Oliver Dempsey
|00353 (0)502 26263
|00353 (0)86 8219430
|
|----- Original Message -----
|From: "Leo Scott" <leoscott@c...>
|To: "Access" <access@p...>
|Sent: Wednesday, November 20, 2002 8:21 AM
|Subject: [access] RE: find and replace not working in the header footer
|
|
|> That code was written and run in Word just as a test/demo of how
|to do it.
|> To run it from Access you will have to set a reference to the
|Word library
|> and prefix the properties and methods with a word application object
|> reference.  I assumed you had already knew you needed to do that
|since you
|> seemed to be accessing Word documents from Access in your
|initial question.
|>
|> |-----Original Message-----
|> |From: odempsey@b... [mailto:odempsey@b...]
|> |Sent: Tuesday, November 19, 2002 1:57 PM
|> |To: Access
|> |Subject: [access] RE: find and replace not working in the header footer
|> |
|> |
|> |Hi Leo
|> |this is turning out to be a complicated issue, I tried that piece
|> |of code and I got the following
|> |error with regard to
|> |For Each HF In sec.Headers
|> |
|> |compile error
|> |Method or Data Member not found
|> |
|> |It is referring to .Headers
|> |
|> |What does this mean?
|> |
|> |thanks so much for your help
|> |
|> |
|> |Kind Regards
|> |Oliver Dempsey
|> |
|> |
|> |
|> |----- Original Message -----
|> |From: "Leo Scott" <leoscott@c...>
|> |To: "Access" <access@p...>
|> |Sent: Tuesday, November 19, 2002 4:15 PM
|> |Subject: [access] RE: find and replace not working in the header footer
|> |
|> |
|> |> Public Sub SearchWholeDocument()
|> |>    Dim sec As Section
|> |>    Dim HF As HeaderFooter
|> |>    Dim blnFound As Boolean
|> |>    Dim strValue As String
|> |>    Dim rng As Range
|> |>
|> |>    strValue = "something"
|> |>    blnFound = False
|> |>    With ActiveDocument
|> |>       If Not FindText(.Content, strValue) Then
|> |>          For Each sec In .Sections
|> |>             For Each HF In sec.Headers
|> |>                Set rng = HF.Range
|> |>                rng.WholeStory
|> |>                If FindText(rng, strValue) Then
|> |>                   blnFound = True
|> |>                   Exit For
|> |>                End If
|> |>             Next
|> |>          If blnFound Then
|> |>             Exit For
|> |>          End If
|> |>          Next
|> |>       Else
|> |>          blnFound = True
|> |>       End If
|> |>    End With
|> |> Debug.Print blnFound
|> |> End Sub
|> |>
|> |> Private Function FindText(ByVal rng As Range, _
|> |>                           ByVal Value As String) As Boolean
|> |>    FindText = False
|> |>    With rng.Find
|> |>       .ClearFormatting
|> |>       .Text = Value
|> |>       .Replacement.Text = ""
|> |>       .Forward = True
|> |>       .Wrap = wdFindContinue
|> |>       .Format = False
|> |>       .MatchCase = False
|> |>       .MatchWholeWord = False
|> |>       .MatchWildcards = False
|> |>       .MatchSoundsLike = False
|> |>       .MatchAllWordForms = False
|> |>       .Execute
|> |>       If .Found Then FindText = True
|> |>    End With
|> |> End Function
|> |>
|> |> |-----Original Message-----
|> |> |From: odempsey@b... [mailto:odempsey@b...]
|> |> |Sent: Tuesday, November 19, 2002 2:59 AM
|> |> |To: Access
|> |> |Subject: [access] RE: find and replace not working in the
|header footer
|> |> |
|> |> |
|> |> |Hi Leo
|> |> |thanks for your reply.  Can you show me the quick test program
|> |> |that you did to find text in a header
|> |> |because I haven't been successful in doing it yet.
|> |> |
|> |> |I will post the query on the word vba forum as well although there
|> |> |seems to very little activity on
|> |> |it.
|> |> |
|> |> |Many Thanks
|> |> |Oliver Dempsey
|> |>
|> |>
|> |>
|> |
|> |
|> |
|>
|>
|>
|
|

Message #9 by <odempsey@b...> on Thu, 21 Nov 2002 20:38:48 -0000
Hi Leo
thanks so much, I really appreciate it!

Thanks again
Oliver


----- Original Message ----- 
From: "Leo Scott" <leoscott@c...>
To: "Access" <access@p...>
Sent: Wednesday, November 20, 2002 4:54 PM
Subject: [access] RE: find and replace not working in the header footer


> I won't have time until this weekend but then I will set up a trial run from
> Access and see what I can come up with for you.
> 
> |-----Original Message-----
> |From: odempsey@b... [mailto:odempsey@b...]
> |Sent: Wednesday, November 20, 2002 4:22 AM
> |To: Access
> |Subject: [access] RE: find and replace not working in the header footer
> |
> |
> |Hi Leo
> |yes, I am pretty new to automation but I was successfully
> |acheiving it as follows:
> |
> |    Set m_objWord = New Word.Application
> |
> |        Set m_objDoc = m_objWord.Documents.Add(m_strTEMPLATEDIR &
> |m_strTHOMASPROPOSALTEMPLATE)
> |
> |inserting bookmarks, saving and printing etc.
> |
> |I thought it should be just a matter of changing your line 'With
> |ActiveDocument'  to
> |'With m_objWord.ActiveDocument'
> |
> |but that doesn't seem to be the case.
> |
> |Any ideas?
> |
> |
> |
> |Kind Regards
> |Oliver Dempsey
> |00353 (0)502 26263
> |00353 (0)86 8219430
> |
> |----- Original Message -----
> |From: "Leo Scott" <leoscott@c...>
> |To: "Access" <access@p...>
> |Sent: Wednesday, November 20, 2002 8:21 AM
> |Subject: [access] RE: find and replace not working in the header footer
> |
> |
> |> That code was written and run in Word just as a test/demo of how
> |to do it.
> |> To run it from Access you will have to set a reference to the
> |Word library
> |> and prefix the properties and methods with a word application object
> |> reference.  I assumed you had already knew you needed to do that
> |since you
> |> seemed to be accessing Word documents from Access in your
> |initial question.
> |>
> |> |-----Original Message-----
> |> |From: odempsey@b... [mailto:odempsey@b...]
> |> |Sent: Tuesday, November 19, 2002 1:57 PM
> |> |To: Access
> |> |Subject: [access] RE: find and replace not working in the header footer
> |> |
> |> |
> |> |Hi Leo
> |> |this is turning out to be a complicated issue, I tried that piece
> |> |of code and I got the following
> |> |error with regard to
> |> |For Each HF In sec.Headers
> |> |
> |> |compile error
> |> |Method or Data Member not found
> |> |
> |> |It is referring to .Headers
> |> |
> |> |What does this mean?
> |> |
> |> |thanks so much for your help
> |> |
> |> |
> |> |Kind Regards
> |> |Oliver Dempsey
> |> |
> |> |
> |> |
> |> |----- Original Message -----
> |> |From: "Leo Scott" <leoscott@c...>
> |> |To: "Access" <access@p...>
> |> |Sent: Tuesday, November 19, 2002 4:15 PM
> |> |Subject: [access] RE: find and replace not working in the header footer
> |> |
> |> |
> |> |> Public Sub SearchWholeDocument()
> |> |>    Dim sec As Section
> |> |>    Dim HF As HeaderFooter
> |> |>    Dim blnFound As Boolean
> |> |>    Dim strValue As String
> |> |>    Dim rng As Range
> |> |>
> |> |>    strValue = "something"
> |> |>    blnFound = False
> |> |>    With ActiveDocument
> |> |>       If Not FindText(.Content, strValue) Then
> |> |>          For Each sec In .Sections
> |> |>             For Each HF In sec.Headers
> |> |>                Set rng = HF.Range
> |> |>                rng.WholeStory
> |> |>                If FindText(rng, strValue) Then
> |> |>                   blnFound = True
> |> |>                   Exit For
> |> |>                End If
> |> |>             Next
> |> |>          If blnFound Then
> |> |>             Exit For
> |> |>          End If
> |> |>          Next
> |> |>       Else
> |> |>          blnFound = True
> |> |>       End If
> |> |>    End With
> |> |> Debug.Print blnFound
> |> |> End Sub
> |> |>
> |> |> Private Function FindText(ByVal rng As Range, _
> |> |>                           ByVal Value As String) As Boolean
> |> |>    FindText = False
> |> |>    With rng.Find
> |> |>       .ClearFormatting
> |> |>       .Text = Value
> |> |>       .Replacement.Text = ""
> |> |>       .Forward = True
> |> |>       .Wrap = wdFindContinue
> |> |>       .Format = False
> |> |>       .MatchCase = False
> |> |>       .MatchWholeWord = False
> |> |>       .MatchWildcards = False
> |> |>       .MatchSoundsLike = False
> |> |>       .MatchAllWordForms = False
> |> |>       .Execute
> |> |>       If .Found Then FindText = True
> |> |>    End With
> |> |> End Function
> |> |>
> |> |> |-----Original Message-----
> |> |> |From: odempsey@b... [mailto:odempsey@b...]
> |> |> |Sent: Tuesday, November 19, 2002 2:59 AM
> |> |> |To: Access
> |> |> |Subject: [access] RE: find and replace not working in the
> |header footer
> |> |> |
> |> |> |
> |> |> |Hi Leo
> |> |> |thanks for your reply.  Can you show me the quick test program
> |> |> |that you did to find text in a header
> |> |> |because I haven't been successful in doing it yet.
> |> |> |
> |> |> |I will post the query on the word vba forum as well although there
> |> |> |seems to very little activity on
> |> |> |it.
> |> |> |
> |> |> |Many Thanks
> |> |> |Oliver Dempsey
> |> |>
> |> |>
> |> |>
> |> |
> |> |
> |> |
> |>
> |>
> |>
> |
> |
> 
> 
> 


  Return to Index