Hi!
I am trying to adapt some code for my needs however, whilst the message is
correct.
An error message says the file cannot be found?
Thanks for you help in advance.
Sub Something()
Dim cCol As Collection
Dim sStr As String
Dim lCnt As Long
Set cCol = New Collection
sStr = Dir("C:\man\*.doc", vbNormal)
While sStr <> ""
cCol.Add sStr
sStr = Dir
Wend
For lCnt = 1 To cCol.Count
MsgBox cCol.Item(lCnt)
Documents.Open cCol.Item(lCnt)
' your code, beware of what you are doing
ActiveDocument.Close
Next
End Sub
old man - 09 Jul 2007 01:08 GMT
Hi,
I just ran your code against a folder with fifteen word documents and it
worked fine. I had one document that was read only and it prompted me as to
how to open it and it worked.
You should add error handling to your code such as this (error handling is
quite powerful and you can should investigate what you want to do when your
program encounters a problem - you may want to stop or resume opening the
remaining
files in the folder):
on error goto errhandle1
...
exit sub
errhandle1:
msgbox "Error in opening file: " & cCol.Item(lCnt) & vbcrlf & "Error - "
& err.number & " - " & err.description,vbCritical,"Error in opening group of
Word Docs"
end sub
> Hi!
>
[quoted text clipped - 24 lines]
>
> End Sub