sort appending order of documents

F

FotoArt

hello everyone
I'm using the following code to append some files.
the problem is it is appending first the last one I select.
I need to reverse this order.
I want the first file selected to be at the top of the final document. And
the second one second and so on.

Sub joinSelectedFiles()
Dim fd As FileDialog

Application.ScreenUpdating = False
Documents.Add
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant

With fd
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
Selection.InsertFile FileName:=(vrtSelectedItem), _
ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.InsertBreak Type:=wdSectionBreakNextPage
Next vrtSelectedItem
Else
End If
End With

Set fd = Nothing
End Sub


any help would be appreciated
thanks
ahmed
 
D

Doug Robbins - Word MVP

Sub joinSelectedFiles()
Dim fd As FileDialog
Dim docrange as Range

Application.ScreenUpdating = False
Documents.Add
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant

With fd
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
Set docrange = ActiveDocument.Range
docrange.Collapse wdCollapseEnd
docrange.InsertBreak wdSectionBreakNextPage
Set docrange = ActiveDocument.Range
docrange.Collapse wdCollapseEnd
docrange.InsertFile FileName:=(vrtSelectedItem), _
ConfirmConversions:=False, Link:=False,
Attachment:=False
Next vrtSelectedItem
End If
End With

Set fd = Nothing
End Sub


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

FotoArt

hello doug
thanx for the reply
the code isnt working as i expected

lets say I have
file1
fille2
file3
file4

when inserted the documents should appear in the same order(the order i
selected) in the new document.
but what happens is file4 is at the top of the new document. The rest of the
documents are inserted correctly.
is there anyway i can insert the documents in the correct order.

heres the code im using
__________________________
Sub joinSelectedDocs()
Dim fd As FileDialog
Application.ScreenUpdating = False
Documents.Add

Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant

With fd
.AllowMultiSelect = True
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
Selection.InsertFile FileName:=(vrtSelectedItem), _
ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.InsertBreak Type:=wdSectionBreakNextPage
Next vrtSelectedItem
Else
End If
End With
Set fd = Nothing
End Sub
____________________________

any help is appreciated
thanx
ahmed
 
D

Doug Robbins - Word MVP

The code that you say you are using is nothing like that which I suggested.

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

FotoArt

hello doug
I posted the wrong code.
Im using the code u posted and made no difference.
the result is just the same.
The last file I select ends up at the top of the compiled document. But I
want the documents appear in the order I select them
that is If i select file1 first it should appear on top of the page. the
second file second and the third one third.
But whats happening with the code u posted is thelast file I selected
appeared at the top the rest was ok.
If u can tell me how I can makw the last file I select appear last on the
document would be a great help.

any help is appreciated.

thanx
ahmed
 
D

Doug Robbins - Word MVP

The issue appears to be that even using

For i = 1 To .SelectedItems.Count
MsgBox .SelectedItems(i)
Next

The last item in the list of selected items is the first item that is
displayed.

Easiest way to work around this would be to modify the code so that it is
the equivalent of

For i = 2 To .SelectedItems.Count
MsgBox .SelectedItems(i)
Next
MsgBox .SelectedItems(1)


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

FotoArt

hello doug

thanx for the responses.
The method u suggested is not working.
let me tell u what im doing n trying to achieve.
I have the FileDialogFilePicker open there is a list of files shown in the
picker. What im doing is clicking the files in a particular order(the order
in which i want them to appear in the final document), in the hope that WORD
is making the selected items list as I click them.
But what I have found is that Word doesnt consider the order in which I
clicked them but it takes the list of the filenames clicked and process in
the order that is listed in the FileDialogFilePicker.
Is there a way I could make Word make the selectedItems list in the order I
clicked or could there be a way in which I could capture the clicked order so
that I could go thru the list of selected items in that order.

Hope Im clear.
Any help in the right direction will be appreciated.

thanx
ahmed
 
D

Doug Robbins - Word MVP

I think that you will have to use a userform with a couple of listboxes, one
of which you populate with the list of all of the files and the other you
populate with the files that you select from the first listbox in the order
that you select them and then you can insert the files from the second list
box in the order that they appear in that listbox.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top