Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-12-2024, 12:29 AM
HenriqueSanches HenriqueSanches is offline Localizar e selecionar intervalo entre 2 textos Windows 10 Localizar e selecionar intervalo entre 2 textos Office 2013
Novice
Localizar e selecionar intervalo entre 2 textos
 
Join Date: Jul 2024
Posts: 1
HenriqueSanches is on a distinguished road
Default Localizar e selecionar intervalo entre 2 textos

Preciso selecionar e colocar 1 intervalo com vários parágrafos e colocar todos no mesmo parágrafo sem alterar o restante do documento.
Estou tentando fazer esta alteração com o código abaixo, porém sem sucesso.
Alguém pode me ajudar?


Code:
Sub 4()
    Dim startText As String
    Dim endText As String
    Dim startPos As Long
    Dim endPos As Long
    Dim doc As Document
    Dim rng As Range
    Dim searchPos As Long
  

    startText = "End.: "
    endText = "Bairro: "

    Set doc = ActiveDocument
    searchPos = 1
    Do
        startPos = InStr(searchPos, doc.Content.Text, startText)
        If startPos = 0 Then Exit Do
        endPos = InStr(startPos + Len(startText), doc.Content.Text, endText)
        If endPos = 0 Then Exit Do
        Set rng = doc.Range(startPos - 1, endPos - 1)
        'rng.Font.Color = wdColorRed
        rng.Select
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.MoveDown Unit:=wdLine, Count:=1
        searchPos = endPos + Len(endText)
    Loop
End Sub
Reply With Quote
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 03:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft