Transforming adresses into full text

T

troubadour

I have a document (produced by mail merge from a ms-access query),
containing many full paths of other documents (such as C:\mydoc\rose.doc).
The adresses are always between two # signs (#C:\mydoc\rose.doc#), and there
is no other # in the document for other purpose, i'm sure :)

I would like to make a macro doing this : detecting each adress, then
opening the document with this file name, selecting the whole text of the
doc, copying it into the clipboard, closing the document, then pasting the
clipboard into the main document (and so on for each adress until the end of
the main document).
Is it reasonable ?
Who can help me (I’m a newby with VB, and not very good yet to modify the
code produced by a macro nor to debug)
Thank you
Toubadour
 
A

Anand.V.V.N

Hi troubadour,

You can do this in visual basic. By any chance you have used the string
manuplation in Visual Basic by the way?

Any way here is what you do. In a Visual Basic project, add reference to
Word 8.0, just check about this, it should be 8.0, though tis is not the
whole code, this is a basic code and will give you a overview as how the
program flows, I'll post the whole code

In a command button click event what you can do is use the

dim objword as word
dim cleanupstr as string

dim filetoopen as string

set objword=createobject("","Word.application")


Documents.Open filename confirmconversions:=True, Readonly:=True


With ActiveDocument.Content

' for each sentence in the document

For i = 1 To .Sentences.Count


cleanupstr = .Sentences.Item(i)

If Mid$(cleanupstr, 1, 1) = "#" Then
filetoopen=mid$(cleanupstr,2,len(cleanupstr)-2)

Documents.Open filetoopen confirmconversions:=True, Readonly:=True
ActiveDocument.Content.Copy
activedocument.close
ActiveDocument.Content.InsertAfter Selection.Paste

Else
End If
Next i
End With


I am not sure about the pasting into the document though, insertafter or
insertmethod can be used to insert the content, I am not sure if
selection.paste works not not. Any way before you try on the actual documents
you can use this code on some test documents and try, to be on safe side.

Hope this code helps you.

Anand
 

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