ap7
04-13-2016, 10:14 AM
Greetings to all the experts,
thank you for reading my post.:)
I am new to vba programs.
I found a macro - I can't post link here but I believe the author is Doug Graham found on msdn.
Which allows me to search and replace from a spreadsheet source.
I am further speculating whether it is possible at all to insert source documents similarly?
That is search for the code in word documents listed in Column A -
if found in the document - insert the source document
Move on to next document
Here is a snapshot of the spreadsheet that lists sample files. There are 100+ files listed
15914
I have been using this below
Sub ReplaceFromXL()
Dim xlapp As Object
Dim xlbook As Object
Dim xlsheet As Object
Dim xlrange1 As Object
Dim xlrange2 As Object
Dim myarray As Variant
Dim Findarray As Variant
Dim Replarray As Variant
On Error Resume Next
Set xlapp = GetObject(, "Excel.Application")
If Err Then
bstartApp = True
Set xlapp = CreateObject("Excel.Application")
End If
On Error GoTo 0
With xlapp
Set xlbook = .Workbooks.Open("C:\Users\APPC\Desktop\Replace.xlsx")
Set xlsheet = xlbook.Worksheets(1)
With xlsheet
Set xlrange1 = .Range("A1", .Range("A1").End(4))
Set xlrange2 = .Range("B1", .Range("B1").End(4))
Findarray = xlrange1.Value
Replarray = xlrange2.Value
End With
End With
If bstartApp = True Then
xlapp.quite
End If
Set xlapp = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing
Set xlrange1 = Nothing
Set xlrange2 = Nothing
For i = 2 To UBound(Findarray)
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = Findarray(i, 1)
.Replacement.Text = Replarray(i, 1)
.MatchWildcards = False
.Wrap = wdFindContinue
.MatchCase = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
End Sub
I would like to search for the code in my documents and then insert the corresponding source document.
If an expert would be kind enough to nudge me in the right direction that would be a start.
The documents will be in a folder that need to be searched.
If the code from the column is found in a document - insert the appropriate source document.
I have hundreds of documents that I am editing and manually it is becoming a very difficult task.
Any advice on this appreciated
many thanks for your time in advance
ap7
thank you for reading my post.:)
I am new to vba programs.
I found a macro - I can't post link here but I believe the author is Doug Graham found on msdn.
Which allows me to search and replace from a spreadsheet source.
I am further speculating whether it is possible at all to insert source documents similarly?
That is search for the code in word documents listed in Column A -
if found in the document - insert the source document
Move on to next document
Here is a snapshot of the spreadsheet that lists sample files. There are 100+ files listed
15914
I have been using this below
Sub ReplaceFromXL()
Dim xlapp As Object
Dim xlbook As Object
Dim xlsheet As Object
Dim xlrange1 As Object
Dim xlrange2 As Object
Dim myarray As Variant
Dim Findarray As Variant
Dim Replarray As Variant
On Error Resume Next
Set xlapp = GetObject(, "Excel.Application")
If Err Then
bstartApp = True
Set xlapp = CreateObject("Excel.Application")
End If
On Error GoTo 0
With xlapp
Set xlbook = .Workbooks.Open("C:\Users\APPC\Desktop\Replace.xlsx")
Set xlsheet = xlbook.Worksheets(1)
With xlsheet
Set xlrange1 = .Range("A1", .Range("A1").End(4))
Set xlrange2 = .Range("B1", .Range("B1").End(4))
Findarray = xlrange1.Value
Replarray = xlrange2.Value
End With
End With
If bstartApp = True Then
xlapp.quite
End If
Set xlapp = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing
Set xlrange1 = Nothing
Set xlrange2 = Nothing
For i = 2 To UBound(Findarray)
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = Findarray(i, 1)
.Replacement.Text = Replarray(i, 1)
.MatchWildcards = False
.Wrap = wdFindContinue
.MatchCase = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
End Sub
I would like to search for the code in my documents and then insert the corresponding source document.
If an expert would be kind enough to nudge me in the right direction that would be a start.
The documents will be in a folder that need to be searched.
If the code from the column is found in a document - insert the appropriate source document.
I have hundreds of documents that I am editing and manually it is becoming a very difficult task.
Any advice on this appreciated
many thanks for your time in advance
ap7