Thread: script help!
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Miker Miker is offline
external usenet poster
 
Posts: 7
Default script help!

i'm trying to modify this script:


Private Sub UserForm_Initialize()

Dim FileList(), i As Long, x, n As Long, fName As String

FilePath = "F:\Sec\History\" 'change to suit

fName = Dir(FilePath & "*.xls")

i = 1

Do While fName < ""

ReDim Preserve FileList(1 To i)

FileList(i) = fName

i = i + 1

fName = Dir()

Loop

ReDim Preserve FileList(1 To i - 1)

With Me.ListBox1

.Clear

.List = FileList

End With

End Sub


What i'm trying to do is, lets say i'm working on sheet "MARCH" and I want
to see what other workbooks in directory F:\Sec\History\ contain the
worksheet "MARCH". I want the listbox to show the workbooks that do contain
the worksheet and ignore the other workbooks that do not . I have a command
button that opens up the selected workbook:


Private Sub CommandButton1_Click()

Dim i As Long, wb As Workbook

With Me.ListBox1

For i = 0 To .ListCount - 1

If .Selected(i) = True Then

Set wb = Workbooks.Open(FilePath & .List(i), UpdateLinks:=0)

wb.Activate

Exit For

End If

Next

End With

End Sub



Is it possible I can get it work work this way?