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 / Excel / New Users / January 2007

Tip: Looking for answers? Try searching our database.

GetOpenFile question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gw.boswell@gmail.com - 15 Jan 2007 16:18 GMT
Can someone explain to me why when the following code executes, the
filename shown in the message box for the first iteration is the last
file name selected in the multiple selection.  The second iteration
show the first file name selected and continues on in order until the
next to last file name selected.

Dim FileToOpen As Variant

FileToOpen = Application.GetOpenFilename("TableFiles (*.prn), *.prn", ,
"Name of Files to Use", , True)

counter = 1

Do While counter <= UBound(FileToOpen)

MsgBox FileToOpen(counter)

counter = counter + 1

Loop

End Sub

TIA

Garry
Bob Phillips - 15 Jan 2007 16:43 GMT
I don't think it is anything to do with the selection order, I think it is
to do with the OS, and where it thinks they are. When you see a list of
files, it is always ordered in some way, but that has nothing to do with the
way that it is stored.

Signature

HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

> Can someone explain to me why when the following code executes, the
> filename shown in the message box for the first iteration is the last
[quoted text clipped - 22 lines]
>
> Garry
gw.boswell@gmail.com - 15 Jan 2007 17:04 GMT
OK, I can accept that. However, I need to address the file names in
order.  Any suggestions as to how to do that?

> I don't think it is anything to do with the selection order, I think it is
> to do with the OS, and where it thinks they are. When you see a list of
[quoted text clipped - 34 lines]
> >
> > Garry
Bob Phillips - 15 Jan 2007 17:37 GMT
You could sort the array

Dim FileToOpen As Variant
Dim counter As Long
FileToOpen = Application.GetOpenFilename("TableFiles (*.prn), *.prn", , _
   "Name of Files to Use", , True)

Call ShellSort(FileToOpen)

counter = 1

Do While counter <= UBound(FileToOpen)

MsgBox FileToOpen(counter)

counter = counter + 1

Loop

End Sub

Public Sub ShellSort(ByRef aryToSort)
Dim i As Long, j As Long
Dim iLow As Long, iHigh As Long
Dim tmp As Variant
   iLow = LBound(aryToSort)
   iHigh = UBound(aryToSort)
   j = (iHigh - iLow + 1) \ 2
   Do While j > 0
     For i = iLow To iHigh - j
       If aryToSort(i) > aryToSort(i + j) Then
         tmp = aryToSort(i)
         aryToSort(i) = aryToSort(i + j)
         aryToSort(i + j) = tmp
       End If
     Next i
     For i = iHigh - j To iLow Step -1
       If aryToSort(i) > aryToSort(i + j) Then
         tmp = aryToSort(i)
         aryToSort(i) = aryToSort(i + j)
         aryToSort(i + j) = tmp
       End If
     Next i
     j = j \ 2
   Loop
 End Sub

Signature

---
HTH

Bob

(change the xxxx to gmail if mailing direct)

> OK, I can accept that. However, I need to address the file names in
> order.  Any suggestions as to how to do that?
[quoted text clipped - 39 lines]
>> >
>> > Garry

Rate this thread:






 
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.