find empty line and copy the paragraph above...

G

GUS

I want a macro to search at all documents in a dir and when finds the first
empty line then copy the above paragraph and paste it in a single document.
After that the macro must create a hyperlink from this paragraph to the file
which contain this paragraph.
I hope somebody understood wht i am trying to do.

Every document in this dir starts with a single paragraph (two or three
lines .The paragraph it's a sort description for the rest of the document)

I want to make a file with all the first paragraphs (short descriptions)
in which every paragraph will link to the apropriate file.

It's vey easy to do that manually but the files in the dir is 1600 and i
want a macro to do that fast.
 
H

Harold Kless

Hi Gus,
Give this a try
Hi Gus,
Try this (be sure to correct the path to the documents folder)
Sub DocNamesInFolder()
Dim sMyDir As String
Dim sDocName As String
Dim targetDoc As Document
Dim sourceDoc As Document
Set targetDoc = ActiveDocument
' The path to obtain the files.
'modify the path
sMyDir = "C:\My Documents\"
sDocName = Dir(sMyDir & "*.DOC")
'loops thru all the files and opens only Word documents with ".doc"
extension
While sDocName <> ""
'Open each document

Set sourceDoc = Application.Documents.Open(sMyDir & sDocName)
sourceDoc.Select
'select the first paragraph and copy it
Selection.Paragraphs(1).Range.Select
Selection.Copy
'select the original or target document and go to the end of it
targetDoc.Select
Selection.EndKey unit:=wdStory
'paste the text and insert a carriage return at the end
Selection.Paste
Selection.InsertParagraphAfter
'add a hyperlink to the file
Selection.Hyperlinks.Add Anchor:=Selection.Range, _
Address:=sMyDir & sDocName
'close the source document and release the variable
sourceDoc.Close 0
Set sourceDoc = Nothing


' Get next file name.
sDocName = Dir()
Wend
End Sub

Hope that this is what you are seeking.

--
Harold Kless, MCSD
Support Professional
Microsoft Technical Support for Business Applications
(e-mail address removed)

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top