Uncover the Secret to Automating Word Documents with VBA! Multiple find and replace word document
3.9 هزار بار بازدید -
3 سال پیش
-
Uncover the Secret to Automating
Uncover the Secret to Automating Word Documents with VBA! Multiple find and replace word document using vbw
#msword #microsoftword #excel #findandreplace
Don't hesitate to ask any questions you have in the comments! I will do my best to answer as many questions as possible.
#word #find #replace #multiple #vba
If you liked the video, please consider hitting that like button! Subscribe to the channel to get even more time-saving videos.
Like Facebook Page : Facebook: spreadsheetlovers
Thanks and enjoy
VBA Code
Sub ReplaceFromTableList()
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
'Change the path in the line below to reflect the name and path of the table document
sFname = "C:\Users\admin\Documents\FindReplaceTable.docx"
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
Selection.HomeKey wdStory
With oRng.Find
.MatchCase = True
.MatchWildcards = False
.MatchWholeWord = False
.Text = rFindText.Text
.Replacement.Text = rReplacement.Text
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next I
oChanges.Close wdDoNotSaveChanges
End Sub
#msword #microsoftword #excel #findandreplace
Don't hesitate to ask any questions you have in the comments! I will do my best to answer as many questions as possible.
#word #find #replace #multiple #vba
If you liked the video, please consider hitting that like button! Subscribe to the channel to get even more time-saving videos.
Like Facebook Page : Facebook: spreadsheetlovers
Thanks and enjoy
VBA Code
Sub ReplaceFromTableList()
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
'Change the path in the line below to reflect the name and path of the table document
sFname = "C:\Users\admin\Documents\FindReplaceTable.docx"
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
Selection.HomeKey wdStory
With oRng.Find
.MatchCase = True
.MatchWildcards = False
.MatchWholeWord = False
.Text = rFindText.Text
.Replacement.Text = rReplacement.Text
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next I
oChanges.Close wdDoNotSaveChanges
End Sub
3 سال پیش
در تاریخ 1399/11/24 منتشر شده
است.
3,929
بـار بازدید شده