Well, let's try a variation on the theme.
'---------------------------------
Sub InsertintoAllDocumentsInaFolder()
Dim MyPath As String
Dim MyName As String
Dim Mydoc As Document
Dim MyRange As Range
'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With
'strip quotation marks from path
If Len(MyPath) = 0 Then Exit Sub
If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If
'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
Set Mydoc = Documents.Open(MyName)
Set MyRange = Mydoc.Range
MyRange.Collapse wdCollapseStart
MyRange.InsertFile FileName:="C:\folder\filename.doc"
Mydoc.Save
Mydoc.Close
MyName = Dir
Loop
End Sub
'---------------------------------
The difference is in using a Range instead of the Selection. Because
the Selection refers to the location of the cursor at the time,
opening and closing a series of documents could cause some confusion.
If you still run into the same behavior, also let us know which line
of the macro is highlighted when the debugger stops it, and the exact
text of any error message you see.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
>Hi Doug and Jay
>
[quoted text clipped - 77 lines]
>> >>>
>> >>> Stuart
Stuart - 02 Nov 2006 12:17 GMT
Hi Jay,
Unfortunately it didnt work again,
The error message
Run time error '5174'
This file could not be found.
Try on or more of the following.
*Check the spelling of the name of the document.
*Try a different file name.
(Test File2.doc)
Hope you can help,
Kind Regards,
Stuart
> Well, let's try a variation on the theme.
>
[quoted text clipped - 132 lines]
> >> >>>
> >> >>> Stuart
Jay Freedman - 02 Nov 2006 17:36 GMT
Hi Stuart,
That message is a lot clearer than many you'll encounter in VBA. :-) I'm
assuming that the highlight is in the line of code
MyRange.InsertFile FileName:="C:\folder\filename.doc"
Whatever you put inside the quotes (I guess from the error message that it
says "Test File2.doc") doesn't match any existing file. If you included a
full path inside the quotes, check the path for spelling errors, missing or
extra spaces, etc. If you didn't include a full path, do that -- the system
is probably looking in the wrong folder.

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
> Hi Jay,
>
[quoted text clipped - 150 lines]
>>>>>>>
>>>>>>> Stuart
Stuart - 02 Nov 2006 18:16 GMT
Hi Jay,
The insertion of the pages works on the first file in the folder but
then that runtime error appears when trying to do the process on the
second file.
Hope this clarifies everything,
Thanks
Stuart
> Hi Stuart,
>
[quoted text clipped - 170 lines]
> >>>>>>>
> >>>>>>> Stuart
Doug Robbins - Word MVP - 02 Nov 2006 20:02 GMT
Exactly what line of code is highlighted when you click on debug after the
error occurs?

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Hi Jay,
>
[quoted text clipped - 186 lines]
>> >>>>>>>
>> >>>>>>> Stuart
Stuart - 02 Nov 2006 21:05 GMT
Hi Doug,
it is debugging on this line,
MyRange.InsertFile FileName:="D:\test\File to insert.doc"
This is the file that I want to insert into the other documents.
It doesnt even work on a file at all now,
Should I post my posting elsewhere see if someone else may be able to
help?
Thanks for your time ,
Stuart
> Exactly what line of code is highlighted when you click on debug after the
> error occurs?
[quoted text clipped - 197 lines]
> >> >>>>>>>
> >> >>>>>>> Stuart
Doug Robbins - Word MVP - 02 Nov 2006 22:35 GMT
Well, when I set up a folder with some files to try this on, it bombed out
on the line
Set Mydoc = Documents.Open(MyName)
which seems to be because Word is getting confused about where the files
are. The following modified code overcame that problem however
Dim MyPath As String
Dim MyName As String
Dim Mydoc As Document
Dim MyRange As Range
'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With
'strip quotation marks from path
If Len(MyPath) = 0 Then Exit Sub
If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If
'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
Set Mydoc = Documents.Open(MyPath & MyName)
Set MyRange = Mydoc.Range
MyRange.Collapse wdCollapseStart
MyRange.InsertFile FileName:="C:\New Folder\Text to insert.docx"
Mydoc.SaveAs MyName
Mydoc.Close
MyName = Dir
Loop

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Hi Doug,
>
[quoted text clipped - 225 lines]
>> >> >>>>>>>
>> >> >>>>>>> Stuart