![]() |
Network drive problems
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 |
Network drive problems
DMB
I tested your code (the first part) and it worked fine for me? |
Network drive problems
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 DMB wrote: 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 -- Dave Peterson |
All times are GMT +1. The time now is 07:09 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com