LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default script help!

ps.

Instead of looping through all the files and worksheets multiple times, I think
I would use a hidden worksheet (in the workbook with the userform???).

Then depending on the number of expected files or the number of expected
worksheets per file, I'd create a table of filenames (in row 1) and worksheets
in that file (rows 2 to ###). (Or the same info transposed.)

Then I could just inspect those ranges to find the matching workbooks.



miker wrote:

Hi Dave, thanks for the example.
I have this script that kind of does what I want. (shown below)
Let me explain what it does. When I hit a button, it runs the script, it has
two list boxes, on the left, and one on the right, after it does it run, it
list's all the workbooks in a specified directory on the left listbox. When I
double click on a workbook on the left, it lists all the worksheets in the
right listbox. If i wanted to view a sheet, I would click on a button to open
the workbook up and take me to the sheet.

Now, what I want it to do now is, lets say i'm on sheet "MARCH" and I hit a
button to run the script. I want all workbooks that contain the sheet
"MARCH" to be displayed on the left lsitbox. Then when I double click the
workbook, it will just display the worksheet on the right.

is that doable?

here is the full script:

Public FilePath As String
Public dic As Object
Public oWB As String
Public oWS As String
Private Sub CommandButton1_Click()
Dim i As Long, wb As Workbook, n As Long
With Me.ListBox2
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
oWS = .List(i)
Set wb = Workbooks.Open(FilePath & oWB, UpdateLinks:=0)
wb.Sheets(oWS).Activate
Exit For
End If
Next
End With
End Sub

Private Sub CommandButton2_Click()
Set dic = Nothing
Unload Me
End Sub

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Long, w()
With Me
For i = 0 To .ListBox1.ListCount - 1
If .ListBox1.Selected(i) = True Then
w = dic.Item(.ListBox1.List(i))
With .ListBox2
.Clear
.List = w
End With
oWB = .ListBox1.List(i)
dic.Item(.ListBox1.List(i)) = w
Exit For
End If
Next
End With
End Sub
Private Sub UserForm_Initialize()
Dim FileList(), i As Long, n As Long, fName As String, shtName()
Dim wb As Workbook, ws As Worksheet

Set dic = CreateObject("scripting.dictionary")
dic.comparemode = vbTextCompare

FilePath = "L:\Sec09\AttendanceHistory\"
UserForm1.Caption = "List of xls files in " & FilePath
fName = Dir(FilePath & "*.xls")

On Error GoTo Xit


With Application
.ScreenUpdating = 0
.EnableEvents = 0
.DisplayAlerts = 0
End With
i = 1:
Do While fName < ""
If Not dic.exists(fName) Then
Set wb = Workbooks.Open(FilePath & fName, UpdateLinks:=0)
For Each ws In wb.Worksheets
n = n + 1
ReDim Preserve shtName(1 To n)
shtName(n) = ws.Name
Next
dic.Add fName, shtName
End If
wb.Close False: Set wb = Nothing
Erase shtName: n = 0
fName = Dir()
Loop
With Me.ListBox1
.Clear
.List = dic.keys
End With
Xit:
With Application
.ScreenUpdating = 1
.EnableEvents = 1
.DisplayAlerts = 1
End With

End Sub


--

Dave Peterson
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with script Please Les Stout[_2_] Excel Programming 2 January 15th 08 06:49 PM
VBA, VB Script and VB clara Excel Programming 1 January 14th 08 03:10 PM
help with the VB script Igneshwara reddy[_2_] Excel Worksheet Functions 4 March 6th 07 08:54 PM
Excel 2000/XP script to Excel97 script hat Excel Programming 3 March 2nd 04 03:56 PM
what is a vb script george Excel Programming 1 July 16th 03 09:56 AM


All times are GMT +1. The time now is 09:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"