Re: If..Then statement
From: Dave Peterson (ec35720_at_netscapeXSPAM.com)
Date: 11/17/04
- Next message: JimFor: "Re: VBA Looping Question"
- Previous message: Llobid: "Re: How do I save a document so I won't print many pages of empty ce."
- In reply to: StephanieH: "RE: If..Then statement"
- Next in thread: StephanieH: "Re: If..Then statement"
- Reply: StephanieH: "Re: If..Then statement"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 16 Nov 2004 18:26:51 -0600
I'm not quite sure what you show in the listbox, but maybe this'll give you some
hints:
Option Explicit
Private Sub CommandButton1_Click()
Dim iCtr As Long
Dim myFiles As Variant
myFiles = Array("path\filename1", _
"path\filename2", _
"path\filename3")
With Me.ListBox1
For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) Then
MsgBox .List(iCtr) & vbLf & _
"workbooks.open " & myFiles(iCtr)
End If
Next iCtr
End With
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
For iCtr = 1 To 3
.AddItem "asdf" & iCtr
Next iCtr
End With
End Sub
ps. There probably isn't a good reason to chdir first--if you include the path
in the workbooks.open statement.
pps. Did that chdir really change folders on a UNC path? I'd bet not.
StephanieH wrote:
>
> In hind-sight, I don't think the problem is in the If.. then statement, but
> the MultiSelect property of the List Box since only the last file selected
> will open. I have the MutliSelect property set to 1 but I'm not sure how
> else to tell it to recognize more than one selection.
>
> "StephanieH" wrote:
>
> > I seem to be having a problem with a simple If.. Then statement.
> >
> > I have the following:
> >
> > Private Sub OK_Click()
> >
> >
> > If ListBox1.ListIndex = 0 Then
> > ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\Chargeoff
> > Trends"
> > Workbooks.Open Filename:= _
> > "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery
> > MIS\Chargeoff Trends\ADU Chargeoffs.xls"
> >
> >
> > If ListBox1.ListIndex = 1 Then
> > ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\Chargeoff
> > Trends"
> > Workbooks.Open Filename:= _
> > "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery
> > MIS\Chargeoff Trends\Agency Chargeoffs.xls"
> >
> >
> >
> >
> > If ListBox1.ListIndex = 2 Then
> > ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\Chargeoff
> > Trends"
> > Workbooks.Open Filename:= _
> > "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery
> > MIS\Chargeoff Trends\Attorney Chargeoffs.xls"
> >
> >
> >
> > If ListBox1.ListIndex = 3 Then
> > ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\Chargeoff
> > Trends"
> > Workbooks.Open Filename:= _
> > "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery
> > MIS\Chargeoff Trends\Deceased Chargeoffs.xls"
> >
> >
> >
> >
> > If ListBox1.ListIndex = 4 Then
> > ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\Chargeoff
> > Trends"
> > Workbooks.Open Filename:= _
> > "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery
> > MIS\Chargeoff Trends\Internal Chargeoffs.xls"
> >
> >
> >
> >
> > If ListBox1.ListIndex = 5 Then
> > ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\Chargeoff
> > Trends"
> > Workbooks.Open Filename:= _
> > "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery
> > MIS\Chargeoff Trends\Large Balance Chargeoffs.xls"
> >
> > Unload UserForm1
> >
> > End Sub
> >
> > I'm getting the message "Block If without End if". I've tried adding "End
> > if" between "Unload UserForm1" and End Sub, but that's not working. It's a
> > multiselect ListBox so if I add End If between the ListIndexes it only opens
> > the last file selected.
> >
> > Help...
-- Dave Peterson
- Next message: JimFor: "Re: VBA Looping Question"
- Previous message: Llobid: "Re: How do I save a document so I won't print many pages of empty ce."
- In reply to: StephanieH: "RE: If..Then statement"
- Next in thread: StephanieH: "Re: If..Then statement"
- Reply: StephanieH: "Re: If..Then statement"
- Messages sorted by: [ date ] [ thread ]