GetOpenFile question

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

0
gw.boswell (19)
1/15/2007 4:18:34 PM
excel 39879 articles. 2 followers. Follow

3 Replies
395 Views

Similar Articles

[PageSpeed] 7

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.

-- 
 HTH

Bob Phillips

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

<gw.boswell@gmail.com> wrote in message
news:1168877912.438426.213950@s34g2000cwa.googlegroups.com...
> 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
>


0
bob.NGs1 (1661)
1/15/2007 4:43:26 PM
OK, I can accept that. However, I need to address the file names in
order.  Any suggestions as to how to do that?

Bob Phillips wrote:
> 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.
>
> --
>  HTH
>
> Bob Phillips
>
> (replace somewhere in email address with gmail if mailing direct)
>
> <gw.boswell@gmail.com> wrote in message
> news:1168877912.438426.213950@s34g2000cwa.googlegroups.com...
> > 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
> >

0
gw.boswell (19)
1/15/2007 5:04:43 PM
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


-- 
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


<gw.boswell@gmail.com> wrote in message 
news:1168880682.676238.295470@38g2000cwa.googlegroups.com...
> OK, I can accept that. However, I need to address the file names in
> order.  Any suggestions as to how to do that?
>
> Bob Phillips wrote:
>> 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.
>>
>> --
>>  HTH
>>
>> Bob Phillips
>>
>> (replace somewhere in email address with gmail if mailing direct)
>>
>> <gw.boswell@gmail.com> wrote in message
>> news:1168877912.438426.213950@s34g2000cwa.googlegroups.com...
>> > 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
>> >
> 


0
bob.NGs (282)
1/15/2007 5:37:41 PM
Reply:

Similar Artilces:

Multiple Fields Query Question
Hi - I need to query multiple fields to find out how many times a specific horse was used for the purpose of a group or private lesson. My query is showing me "all" billing reasons as opposed to only the "lesson" ones. I've pasted the SQL below...is anyone able to help me with this? I just want to see the horses that were used for lessons only. I created this in Design View as I'm only familiar with creating queries that way, so if you could please be specific with any answers, I'd really appreciate it, since I do not know SQL. Thank...

A question of normalization
I've been developing an application for 2 years now that one may refer to as an inventory management database. I use the application on a daily basis to help run my business and it works nicely. I've recently begun to redesign the application and have decided that I come to a crossroads that is well beyond my expertise. I have 3 key tables: 1. tblItems: list of raw materials and other relevant information (12 fields in total) 2. tblSubAssemblies: list of sub assembly items and relevant info (9 fields in total) 3. tblFinishedProducts: list of finished products for resale and relevant i...

Answer to book questions
Hi, everything is a lot less than we actually make it. We are just filling in voids with senseless needs for answers. ...

Re: activation question
Hi Tian, Thanks for the reply, but nothing new in that information. I'm trying to make a custom control that has a drop down window. If I make this window a child of a dialog bar, it's clipped to the dialog bar. If I make it a child of the frame, I can draw on it, but I can't get focus and I can't force it to the top of the z order to get focus even if I call SetWindowPos with insert after the dialog bar or using the constant for top. Specifically how can I make a window that will not be clipped by the dialog bar it's placed in, and will recieve focus? Hi kermit,...

Port questions
Hi All, Just a few questions, wondering if anyone could answer them. 1. Can Exchange server traffic to limited to specific range of port? 2. Is there a recommended range of ports by Microsoft to lock Exchange into? 3. If #2 is no, then how many ports are needed by Exchange (1, 10, 50?). Pick a high range ports say from (62,520+) to lock Exchange into. On Thu, 6 May 2010 11:56:08 -0700, IDK215 <IDK215@discussions.microsoft.com> wrote: >Hi All, > >Just a few questions, wondering if anyone could answer them. > >1. Can Exchange se...

thread question #4
How can I determine in a block of code if the thread it's running in is the same as the main GUI thread? I was trying to use GetCurrentThread to get the thread the function is being called from. Not sure how compare that to GUI thread. On Wed, 21 Dec 2005 13:58:35 -0600, "Eric Margheim" <NOSPAM***eric@prism-grp.com***NOSPAM> wrote: >How can I determine in a block of code if the thread it's running in is the >same as the main GUI thread? > >I was trying to use GetCurrentThread to get the thread the function is being >called from. Not sure how...

Formula Question
I need to do some type of lookup and sum in vba I'd like to use Total Sheet.B5 to return the value Total Sheet.B5 to = 55 if Total Sheet.A5 = Orange Total Sheet A5 = Orange B5 = 55 Sheet 1 A4 = Blue b4 = 5 A5 = Green b5 = 10 A6 = Orange b6 = 15 Sheet 2 A4 = Orange b4 = 10 A5 = Green b5 = 20 A6 = Blue b6 = 30 Sheet 4 A4 = Green b4 = 20 A5 = Orange b5 = 30 A6 = Blue b6 = 40 Thank you for any help Hummm, I can't really tell what you're doing, but look here: http://www.xldynamic.co...

Stupid Question
Hey, This may sound stupid, but, how do you email a knowledge base article to a customer and record it in activities? --> Codeman --< There is no built-in way to do this. You need to copy and paste the KB article into a CRM E-mail. BTW, you can only copy KB article text when you view the article from Workplace in CRM. (If you view the KB article from the Service module's KB Manager, copy functionality is disabled for some reason.) -- Matt Wittemann http://icu-mscrm.blogspot.com "Codeman" wrote: > Hey, > This may sound stupid, but, how do you email a knowledge...

if/then question
Here's what I hope is a pretty basic question. I have 5 rows of inventory data. They are the following: A1: Product Name A2: Product Cost A3: Maximum Qty. Desired on Hand A4: Minimum Qty. Desired on Hand A5: Quantity on Hand Basically, it looks like this: Widget X | 25 | 10 | 4 | 5 I'd like to figure out how to write a formula for cell A6 that would tell me the following: If A5 is greater or equal to A4, then I'd like A6 = 0. If A5 is less than A4, then I'd like A6 = (A3-A5) * A2. Is this possible? Many thanks, Brendan Brendan this should work =IF(A5>...

TreeView question
Hi, A stupid question about TreeView control under VS2003 .NET. I place from toolbox, a TreeView control on my dialog box. It's ID = TV so its name is TV too. Now clicking on a button, i would like to insert some values as roots and some other as items belonging to these roots. How can i do it ? thanks. PS : i'm a rookie in VC++ :-( ...

a few questions....
If anyone can please help me answer the following questions: - How do you define multiple suppliers for one inventory item? - For a matrix item, how do you define the item with various shapes/colors and bring up that item with the item lookup code? - How do you customize receipts in RMS with your own fields? Any help would be great. >If anyone can please help me answer the following questions: > >- How do you define multiple suppliers for one inventory item? F1 Help, Manager Program, Working with your database, Managing supplier information ...

Money 2007 Display question
In Money 2004, I was able to configure the account display to show the bills on the date they were due to be processed. In 2007 it displays the scheduled bills on the date they're to be processed by the bank which is three or four days before when they'll be due. I can't figure out how to change the date displayed to the due date. Thanks, ...

question "File -> Send To -> Mail Receipient"
Dear, I am using all English Windows 98 SE, Office 97 Std SR2, IE 6.0 SP1, Netscape 7.2 Netscape Mail is my default MAPI If I open an XLS file in C:\WINDOWS\TEMP , "Sent to mail receipient" is not work. There was becasue the customer direct open an attachment (which must save in %temp%) then "Compose by anther email" without save the file. -david ...

Very Newbie Question
Hi Imust start by admitting I am not very experienced in the world of Outlook and Exchange but something I find very starnge happens on my network. Client Outlook 2002 Server Excgange 2003 with latest service pack I have set up an internal exchange system whereby the client has only an exchange account. Although the client does have internet access On this client I can email out to; for example hotmail and Gmail succesfully although there are NO external accounts configured I am impressed and yet concerened Is this supposed to happen and how does it work thanks for your time Dave C...

IE8 security add-on question
Is there functionality in IE8, or in an add-on which can block certain information being sent from IE8 to a remote web site. E.g. if my kids started using my PC, can I stop them sending our address, phone number, etc? I'm thinking of an add-on that would block certain text from being sent to an internet site. I know education is the best thing, but who's kids ever do everyhting they're told ;) Thanks for any help. Iain You'll find lots of good ideas & recommendations in this discussion: http://aumha.net/viewtopic.php?t=30095 That being said, Tough Love ...

A few very tough questions..
I recently took over an SBS 2008 installation from a group that had no business installing it in the first place. There were a ton of event viewer errors, Exchange, SBS Console, you name it, they screwed it up. There are 25 users and they never installed antivirus on either the Exchange mailboxes or the client computers. Enough of that.. Here are the few remaining issues. 1. They never ran a best practices tool. When I did Exchange showed a "first administrator group" of an old Exchange 2003 SBS install on another computer that crashed. I don't know how or why it&#...

XsltCompiledTransform question
Here are three things that I thought would be equivalent but are not. Just wondering why: XmlElement foo = doc.CreateElement("foo"); // load it up with a body xslt.Transform (foo, null, new XmlTextWriter(new StringWriter())); xslt.Transform (foo.CreateNavigator(), null, new XmlTextWriter(new StringWriter())); xslt.Transform(new XmlNodeReader(foo), new XmlTextWriter(new StringWriter())); Only the third one applies the transform and produces the expected output. The first two produce nothing. The docs say that passing in an XmlNode or navigator "usually an XmlDocument or ...

Simple Logic question?
Using Excel 2003, I'm trying to build a formula that displays a symbol in a cell to indicate the current date period. There are four rows of data, each representing a calendar quarter Q1, Q2, Q3, and Q4. Each row has a cell which indicates the last transaction date for that period. In the Q1 row, that date is 03/31/08. In the Q2 row, that date is 04/25/08 as that is the most current data set loaded. Q3 and Q4 date cells are blank. The first part of the formula needs to check if there is data by evaluating if the date cell is blank. If it is blank, then the result should be a blank ...

GetOpenFile question
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 I d...

Windows PowerShell Time out question
Wondering if there's a way to limit how long PowerShell will try to get the following information out of a servers WMI. Here's what I've got currently, it works fine so long the servers respond... $a = New-Object -comobject Excel.Application $a.visible = $True $b = $a.Workbooks.Add() $c = $b.Worksheets.Item(1) $c.Cells.Item(1,1) = "Domain" $c.Cells.Item(1,2) = "Server Name" $c.Cells.Item(1,3) = "Operating System" $c.Cells.Item(1,4) = "IP Address" $c.Cells.Item(1,5) = "Service Packs" $c.Cells.Item(1,6) = "Sys...

question about spam
How is it that spam sent to one mailbox will end up in another not mentioned in the "to" address. In other words how is it that spammers get mail destined to Bob in Jim's mailbox? In news:y9CIg.1194$Cq4.62@newssvr25.news.prodigy.net, Mostro <ovelozpleasenospammingme@glasnospampleasefloss.com> typed: > How is it that spam sent to one mailbox will end up in another not > mentioned in the "to" address. In other words how is it that > spammers get mail destined to Bob in Jim's mailbox? The BCC field. It can be used for evil as well as good. ...

VLOOKUP and RAND question
Hi, I have a question regarding the VLOOKUP, RAND, and maybe IF function in Excel. I would greatly appreciate it if anyone can help with m problem. I have 2 columns of data and would like to use a formula fo Column 3. Column 1 = numbers 1, 2, 3 Column 2 = numbers 500, 1000, 1500 associated with Column 1 I would like Column 3 to use the RAND function to randomnly pick fro the numbers in Column 1, then return the value in Column 2. I'm no sure how to do this. Since there is equal probability of the numbers in Column 1 to appear can I just use the RAND function for Column 2 and skip ...

Money Budget Question
My budget is pretty well filled out but in all the major categories I keep getting at the bottom of the categories a grayed out "Unallocated". Normally that would prompt me to go to the "Categorized Transactions", but there aren't any there. It skews my budget numbers badly. Any suggestions on how to fix this? I've got data in this program from 2000 and the release is Money 2006 I believe it means that your main budget category exceeds your individual categories under that main category. For example if you have Income at $5000 and under that you have paychec...

Another receipt question
Any way to choose do not print receipts, but that it still would print upon request (ie after a transaction and by pressing F4) and when printing x and z reports? Best, Manny Yes, you can go into database> register> properties> click receipt printer tab and check box that says " print recipes after asking the cashier" -- Elizabeth M. "mnylen" <mnylen@discussions.microsoft.com> wrote in message news:208665F7-A76A-4BEA-A9A9-7772FC35C3C1@microsoft.com... > Any way to choose do not print receipts, but that it still would print > upon > request (...

query filter question
In publisher 2003, I use my data source from word, for my merge, with a heading titled DATES ,and am having trouble in filtering dates in proper order,in filter I use (DATE) greater than or equal (COMPARE TO) 4-01-01 --- and (DATE) less than (COMPARE TO) 7-01-03, .... In other words I want to send mailers to clients that used my service from April 01 to July 03 I than only get dates between April and July of each yr, I don't get August through March. In word I have no problem doing it. The built in database in Publisher is very basic and always has been. ...