Consulting

Results 1 to 7 of 7

Thread: New line added in header by a replace

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Feb 2017
    Posts
    4
    Location

    New line added in header by a replace

    Hello,

    I have a small and simple problem but i'm not very good with Selection and Range, etc... The problem is that, in the header, when I try to replace some text, a new line is automatically added a the end. Exemple :

    Coca-Cola(end of line)
    blablabla(end of line)
    (end of line)

    vv action vv

    Pepsi(end of line)
    blablabla(end of line)
    (end of line)
    (end of line)


    I just need a solution that prevents this , or a solution that delete last line.

    Here the code used :

    Public Sub ForceCocaToPepsi(ByRef wdocDocument As Word.Document)    Dim lngI As Long
        Dim lngJ As Long
        Dim wrngCurrent As Word.Range
        
        For lngI = 1 To wdocDocument.Sections.Count
            For lngJ = 1 To wdocDocument.Sections(lngI).Headers.Count
                Set wrngCurrent = wdocDocument.Sections(lngI).Headers(lngJ).Range
                If InStr(1, wrngCurrent.Text, "Coca") Then
                    wdocDocument.Sections(lngI).Headers(lngJ).Range.Text = Replace(wrngCurrent.Text, "Coca", "Pepsi")
                End If
            Next lngJ
           
    
        Next lngI

    Thank you,

    Amaury Bianchi
    Last edited by Bamaury; 02-02-2017 at 07:39 AM.

Posting Permissions

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