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 / October 2007

Tip: Looking for answers? Try searching our database.

Making a Process Alphabetical

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
td - 15 Oct 2007 20:13 GMT
I have an ongoing problem.  I use a program written in Access that
manipulates a bunch of Word documents.  I'll spare you the details, but the
program basically does the following...

(1) Creates and opens a new word file (called the "collection document"),
and then creates a header and inserts a blank table of contents.
(2)  Begins opening Word files, one at a time, n a specified folder path.
(3) When each Word file is opened, the program searches for a bookmarked
block of text, copies that text, switches back to the "collection document,"
inserts a heading equal to the filename of the Word document from which it
copied the text, and pastes the text immediately below.
(4) The program loops through all of the documents in the specified folder.
(5) When there are no more documents, the program updates the TOC to show
the page numbers of each heading, and saves and closes the "collection
document."

My problem is...  I want the blocks of text to be alphabetized by their
heading.  I thought that the program would loop through the files in the
folder in alphabetical order, but it seems to use some random order that I
can't figure out.  I'm just using a simple Do While loop to loop through the
files, as shown below

[code establishing variables and such]
myname = Dir(filedir, vbNormal)   ' Retrieve the first entry.
Do While myname <> ""    ' Start the loop.
     If Left(myname, 1) <> "~" Then
       If (GetAttr(filedir & myname) And vbNormal) = vbNormal Then
         If Right$(myname, 4) = ".doc" Then
           Set mydoc = myapp.Documents.Open(filedir & myname, False, True,
False)
           [the code for finding and copying the bookmarks, and pasting
them into the
           collection document, is here]
           'close the file
           mydoc.Close SaveChanges:=False
         End If
       End If
     End If
   myname = Dir
Loop
[code to update TOC, and some other random formatting stuff, and to save and
close the document]

Any idea where it is getting the order to go through the files?  Any way to
change something so that it goes through them in alphabetical order?

Thanks,
td
td - 15 Oct 2007 21:20 GMT
Hmmm...  My problem may have been magically solved.  I just ran the program,
and they're all in alphabetical order.  Very strange, as I've used this for
years and it's never every been like this.  It's like when you bring your car
to the mechanic and it works perfectly.

Only thing I can think of is that we switched from Office 2002 to Office
2003.  Any insight?  I'd love to know what happened.

td

> I have an ongoing problem.  I use a program written in Access that
> manipulates a bunch of Word documents.  I'll spare you the details, but the
[quoted text clipped - 44 lines]
> Thanks,
> td
 
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.