Network drive problems

G

Guest

How do I write the code correctly. The following program won't find the
network drive.
Is there somthing worng with this line?

FilePath = "\\TW Design Server\TW Engineering\DMB Time\"


Private Sub btnCalculate_Click()
TotalHoursToDate.Text = 0
Dim FilePath As String
FilePath = "C:\My Programs\"
FilePath = "\\TW Design Server\TW Engineering\DMB Time\"
Dim FileName(2) As String
FileName(1) = "Time Card 2005.xls"
FileName(2) = "Time Card 2006.xls"

For i = 1 To 2
Workbooks.Open FileName:=FilePath & FileName(i), ReadOnly:=True
Next i

Dim file As Workbook
Dim sht As Worksheet
Dim cel As Range
Dim j As Integer
Dim Total As Double
Total = 0

For Each file In Workbooks
If UCase(file.Name) <> "PERSONAL.XLS" Then
For Each sht In file.Worksheets
For Each cel In sht.Range("F1:F30")
If sht.Cells(cel.Row, cel.Column).Text =
TotalHours.Projects.Text Then
Total = Total + Round(sht.Cells(cel.Row, cel.Column
- 1), 2)
End If
Next cel
Next sht
End If
Next file
TotalHoursToDate.Text = Total
End Sub
 
D

Dave Peterson

You sure that's the correct path?

And just a question:
Wouldn't it be better to loop through those two workbooks--just in case you had
more workbooks open:

For Each file In Workbooks
If UCase(file.Name) <> "PERSONAL.XLS" Then


For i = 1 to 2
For Each sht In workbooks(filename(i)).Worksheets
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top