T
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
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
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