Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Open Word Document VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FIRSTROUNDKO - 08 Jul 2007 20:05 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.