Skip to main content
Pregunta protegida por ComunidadBot
Relanzada por el usuario Comunidad
Editar etiquetas.
Enlace
Rubén
  • 11.5k
  • 7
  • 41
  • 85
se añadieron 129 caracteres en el cuerpo
Origen Enlace
lois6b
  • 7.6k
  • 5
  • 33
  • 54

Tengo hecha esta macro para buscar y reemplazar palabras desde un archivo específico, que en este caso es un documento de Word. 

Mi consulta es cómo:

¿Cómo hago para que en vez de un documento de word, tome el contenido de una lista de excel.?

Éste es el código:

Sub ListaDeBalanceEspPort01()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim rFindText As Range, rReplacement As Range
Dim i As Long
Dim sFname As String
sFname = "C:\Users\tini\Documents\SLAP\ESaPTinc.doc"
Set oDoc = ActiveDocument
Set oChanges = Documents.Open(FileName:=sFname, Visible:=False)
Set oTable = oChanges.Tables(1)
For i = 1 To oTable.Rows.Count
    Set oRng = oDoc.Range
    Set rFindText = oTable.Cell(i, 1).Range
    rFindText.End = rFindText.End - 1
    Set rReplacement = oTable.Cell(i, 2).Range
    rReplacement.End = rReplacement.End - 1
    With oRng.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            Do While .Execute(findText:=rFindText, _
                MatchWholeWord:=False, _
                MatchWildcards:=False, _
                Forward:=True, _
                Wrap:=wdFindContinue) = True
                oRng.Text = rReplacement
            Loop
    End With
Next i
oChanges.Close wdDoNotSaveChanges
End Sub

Dim oChanges As Document, oDoc As Document Dim oTable As Table Dim oRng As Range Dim rFindText As Range, rReplacement As Range Dim i As Long Dim sFname As String sFname = "C:\Users\tini\Documents\SLAP\ESaPTinc.doc" Set oDoc = ActiveDocument Set oChanges = Documents.Open(FileName:=sFname, Visible:=False) Set oTable = oChanges.Tables(1) For i = 1 To oTable.Rows.Count Set oRng = oDoc.Range Set rFindText = oTable.Cell(i, 1).Range rFindText.End = rFindText.End - 1 Set rReplacement = oTable.Cell(i, 2).Range rReplacement.End = rReplacement.End - 1 With oRng.Find .ClearFormatting .Replacement.ClearFormatting Do While .Execute(findText:=rFindText, _ MatchWholeWord:=False, _ MatchWildcards:=False, _ Forward:=True, _ Wrap:=wdFindContinue) = True oRng.Text = rReplacement Loop End With Next i oChanges.Close wdDoNotSaveChanges End Sub

Gracias,

Sol

Tengo hecha esta macro para buscar y reemplazar palabras desde un archivo específico, que en este caso es un documento de Word. Mi consulta es cómo hago para que en vez de un documento de word, tome el contenido de una lista de excel.

Éste es el código:

Sub ListaDeBalanceEspPort01()

Dim oChanges As Document, oDoc As Document Dim oTable As Table Dim oRng As Range Dim rFindText As Range, rReplacement As Range Dim i As Long Dim sFname As String sFname = "C:\Users\tini\Documents\SLAP\ESaPTinc.doc" Set oDoc = ActiveDocument Set oChanges = Documents.Open(FileName:=sFname, Visible:=False) Set oTable = oChanges.Tables(1) For i = 1 To oTable.Rows.Count Set oRng = oDoc.Range Set rFindText = oTable.Cell(i, 1).Range rFindText.End = rFindText.End - 1 Set rReplacement = oTable.Cell(i, 2).Range rReplacement.End = rReplacement.End - 1 With oRng.Find .ClearFormatting .Replacement.ClearFormatting Do While .Execute(findText:=rFindText, _ MatchWholeWord:=False, _ MatchWildcards:=False, _ Forward:=True, _ Wrap:=wdFindContinue) = True oRng.Text = rReplacement Loop End With Next i oChanges.Close wdDoNotSaveChanges End Sub

Gracias,

Sol

Tengo hecha esta macro para buscar y reemplazar palabras desde un archivo específico, que en este caso es un documento de Word. 

Mi consulta es:

¿Cómo hago para que en vez de un documento de word, tome el contenido de una lista de excel?

Éste es el código:

Sub ListaDeBalanceEspPort01()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim rFindText As Range, rReplacement As Range
Dim i As Long
Dim sFname As String
sFname = "C:\Users\tini\Documents\SLAP\ESaPTinc.doc"
Set oDoc = ActiveDocument
Set oChanges = Documents.Open(FileName:=sFname, Visible:=False)
Set oTable = oChanges.Tables(1)
For i = 1 To oTable.Rows.Count
    Set oRng = oDoc.Range
    Set rFindText = oTable.Cell(i, 1).Range
    rFindText.End = rFindText.End - 1
    Set rReplacement = oTable.Cell(i, 2).Range
    rReplacement.End = rReplacement.End - 1
    With oRng.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            Do While .Execute(findText:=rFindText, _
                MatchWholeWord:=False, _
                MatchWildcards:=False, _
                Forward:=True, _
                Wrap:=wdFindContinue) = True
                oRng.Text = rReplacement
            Loop
    End With
Next i
oChanges.Close wdDoNotSaveChanges
End Sub

Gracias,

Sol

Origen Enlace
Sol Lq
  • 1
  • 1
  • 3

Macro para buscar y reemplazar palabras en Word desde una lista de Excel

Tengo hecha esta macro para buscar y reemplazar palabras desde un archivo específico, que en este caso es un documento de Word. Mi consulta es cómo hago para que en vez de un documento de word, tome el contenido de una lista de excel.

Éste es el código:

Sub ListaDeBalanceEspPort01()

Dim oChanges As Document, oDoc As Document Dim oTable As Table Dim oRng As Range Dim rFindText As Range, rReplacement As Range Dim i As Long Dim sFname As String sFname = "C:\Users\tini\Documents\SLAP\ESaPTinc.doc" Set oDoc = ActiveDocument Set oChanges = Documents.Open(FileName:=sFname, Visible:=False) Set oTable = oChanges.Tables(1) For i = 1 To oTable.Rows.Count Set oRng = oDoc.Range Set rFindText = oTable.Cell(i, 1).Range rFindText.End = rFindText.End - 1 Set rReplacement = oTable.Cell(i, 2).Range rReplacement.End = rReplacement.End - 1 With oRng.Find .ClearFormatting .Replacement.ClearFormatting Do While .Execute(findText:=rFindText, _ MatchWholeWord:=False, _ MatchWildcards:=False, _ Forward:=True, _ Wrap:=wdFindContinue) = True oRng.Text = rReplacement Loop End With Next i oChanges.Close wdDoNotSaveChanges End Sub

Gracias,

Sol