Tech Support Forum banner
Status
Not open for further replies.
1 - 8 of 8 Posts

· Registered
Joined
·
7 Posts
Discussion Starter · #1 ·
Hi

I haven't been programming for several years now and i could really use some help.
I want to search one document (doc1) and get the first line in that document. Then i wil have to keep that string and search for the same string in another document(doc2). When i find the string in doc2 i will have to delete the entire section in the doc2 document. Then i will have to find the next line in doc1 etc. etc. Does anyone know how to do this because i am totally lost right now.
Doc1 will be a selection of strings divided by CRLF or by a comma.

Any help will be very welcome.

Many regards
imbr
 

· Registered
Joined
·
7 Posts
Discussion Starter · #3 ·
Re: macro to find and delete

How?
Doc1 is a document created by selecting the numbers from an oracle database and i can't turn every number into a hyperlink. I tried to record a macro and it works for the first number but not for the rest of them.
 

· Moderator , Microsoft Support, MS Office Pro
Joined
·
2,557 Posts
Re: macro to find and delete

Hi imbr,
I want to search one document (doc1) and get the first line in that document. Then i wil have to keep that string and search for the same string in another document(doc2). When i find the string in doc2 i will have to delete the entire section in the doc2 document. Then i will have to find the next line in doc1 etc. etc. Does anyone know how to do this because i am totally lost right now.
Doc1 will be a selection of strings divided by CRLF or by a comma.
I can't see how hyperlinks would help either.

Try the following code, which assumes your source document has 'find' strings separated by paragraph breaks. The code acts on whichever document is active when it runs.
Code:
Sub BulkSectionDelete()
Application.ScreenUpdating = False
Dim RngFnd As Range, RngSch As Range, i As Long
Dim FRDoc As Document, FRList As String
'Load the strings from the reference doc into a text string to be used as an array.
Set FRDoc = Documents.Open("Drive:\FilePath\FindReplaceList.doc")
FRList = FRDoc.Range.Text
FRDoc.Close False
Set FRDoc = Nothing
Set RngSch = ActiveDocument.Range
With RngSch
   'Process each word from the Check List. One paragraph per string is assumed
  For i = 0 To UBound(Split(FRList, vbCr))
    Set RngFnd = RngSch.Duplicate
    With RngFnd.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Replacement.Text = ""
      .MatchWholeWord = False
      .MatchCase = False
      .Text = Split(FRList, vbCr)(i)
      While .Execute
        With RngFnd
          'Delete the entire Section
          .Sections(1).Range.Delete
          '.Collapse wdCollapseEnd
        End With
      Wend
    End With
  Next
End With
Set RngSch = Nothing: Set RngFnd = Nothing
Application.ScreenUpdating = True
End Sub
 

· Moderator , Microsoft Support, MS Office Pro
Joined
·
2,557 Posts
Hi imbr,

FWIW, the macro takes a different approach to what you suggested in your original post: it opens the source file and reads in all the data into a string, closes the file, and only then starts the Find/Replace process, using the stored string as an array of 'Find' elements. This is much more efficient than going back and forth between two documents.
 

· Registered
Joined
·
7 Posts
Discussion Starter · #8 ·
Hi Paul
I agree and i was considering a solution like that but i wasn't able to implement it properly. The sourcefile is a very large file because of the selection i made in sqlplus. I've made a new select that produces a smaller file which makes it much more efficient. It was great fun to implement all of it and to see it work perfectly. Thanks again. :eek:)

imbr
 
1 - 8 of 8 Posts
Status
Not open for further replies.
Top