¦U¦ì¦n¡A
¤£¦n·N«ä¤S¨Ó³Â·Ð¤j®a¤F¡C³Ìªñ¦b¸ÕµÛ§ï¼g¥H¡iµ{¦¡¥æ©ö»EÄ_¬Ö¡j¸Ì±CLCY¤j¤À¨Éªº´Á¥æ©ÒÂàÀÉÀɮסA¸ÕµÛ§âì¥ý¥u¯à¤@¦¸¿é¤J¤@¤ÑªºEXCEL§ï¼g¦¨¥i¥H§å¦¸¿é¤J¦h¤Ñªºª©¥»¡]¤ñ¦p»¡±q¤@Ó¦X¬ù¤ë¥÷ªº¶}ܤé¦Üµ²ºâ¤é¡^¡A¦ý¬O¤@ª½¤£¦¨¥\¡C
¤]´N¬O»¡§Ú·Qn±q´Á¥æ©Ò´£¨Ñªº½L«á¨Cµ§¥æ©ö¸ê®Æ¡].rptÀÉ¡^§å¦¸¿é¤J¦ÜExcel¤¤¡]Excel 2010)¡A¤ñ¦p»¡±q2011-12-15, 2011-12-16,......2012-01-12, 2012-01-13 µ¥µ¥
½Ð¥ýÅý§Úªþ¤W§Úªºcode¡A¦A»¡©ú§Úªº°ÝÃD¡C- Public Sub CommandButton1_Click()
- Dim FilePath As String, FileName As String
- Dim Product As String, Contract As String
- Dim Hr As Long, Min As Long, Sec As Long
- iYear_s = Val(txtYear_start.Text)
- iYear_e = Val(txtYear_end.Text)
- iMonth_s = Val(txtMonth_start.Text)
- iMonth_e = Val(txtMonth_end.Text)
- iDay_s = Val(txtDay_start.Text)
- iDay_e = Val(txtDay_end.Text)
- For Z = iYear_s To iYear_e
- For J = iMonth_s To iMonth_e
- For K = iDay_s To iDay_e
- 'transform number into string
- txtYear = Z & ""
- txtMonth = J & ""
- txtDay = K & ""
- FilePath = ThisWorkbook.Path & "\"
- 'specify the file name to be "Daily_yyyy_mm_dd.rpt"
- If J < 10 And K < 10 Then
- FileName = "Daily_" & txtYear & "_0" & txtMonth & "_0" & txtDay & ".rpt"
- ElseIf J < 10 And K >= 10 Then
- FileName = "Daily_" & txtYear & "_0" & txtMonth & "_" & txtDay & ".rpt"
- ElseIf J >= 10 And K < 10 Then
- FileName = "Daily_" & txtYear & "_" & txtMonth & "_0" & txtDay & ".rpt"
- ElseIf J >= 10 And K >= 10 Then
- FileName = "Daily_" & txtYear & "_" & txtMonth & "_" & txtDay & ".rpt"
- End If
- Product = txtProduct.Text
- Contract = txtContract.Text
- ' count total number of worksheets
- isheetsnumber = ThisWorkbook.Sheets.Count
- ' free the file number for input
- iFNumber = FreeFile
- ' resume if the .rpt file doesn't exist
- On Error GoTo errTrap
- 'input .rpt file
- Open FilePath & FileName For Input As #iFNumber
- SheetsName = Mid(FileName, 7, 10) & "f"
- 'small loop to test if the worksheet exists, exists =true otherwise false
- For iM = 1 To isheetsnumber
- If ThisWorkbook.Worksheets(iM).Name = SheetsName & "" Then ' &"" transform the number to string
- Sheets_Exist = True: Exit For
- Else
- Sheets_Exist = False
- End If
- Next iM
- 'if sheet does not exist, then add one
- If Sheets_Exist = False Then
- Worksheets.Add.Name = SheetsName
- ' move to the end
- ActiveSheet.Move After:=Sheets(isheetsnumber)
- N = 1
- While Not EOF(1)
- Input #iFNumber, A(N, 1), A(N, 2), A(N, 3), A(N, 4), A(N, 5), A(N, 6), A(N, 7), A(N, 8)
- If N = 1 Then
- Sheets(SheetsName).Cells(1, 1) = A(1, 4)
- Sheets(SheetsName).Cells(1, 2) = A(1, 5)
- Sheets(SheetsName).Cells(1, 3) = A(1, 6)
- N = N + 1
- End If
- If A(N, 2) = Product And A(N, 3) = Contract Then
- Sec = Val(Left(Right(Str(A(N, 4)), 2), 2))
- Min = Val(Left(Right(Str(A(N, 4)), 4), 2))
- Hr = Val(Left(Right(Str(A(N, 4)), 6), 2))
- A(N, 9) = Str((Hr * 3600 + Min * 60 + Sec) - 31500)
- Sheets(SheetsName).Cells(N, 1).Value = Val(A(N, 4))
- Sheets(SheetsName).Cells(N, 2).Value = Val(A(N, 5))
- Sheets(SheetsName).Cells(N, 3).Value = Val(A(N, 6))
- Sheets(SheetsName).Cells(N, 4).Value = Val(A(N, 9))
- N = N + 1
- End If
- Wend
- Close 1
- N = N - 2
- End If
-
- MsgBox ("Total amount of data is " & Str(N))
- errTrap:
- Resume Conti
- Conti:
- Next K
- Next J
-
- Next Z
- End Sub
½Æ»s¥N½X ¦pªG¬O¦P¤@Ó¤ë¥÷©Î¬O¦~¥÷ªº¸Ü¨S¦³°ÝÃD¡A¦ý¬O¥X²{¸ó¤ëªº¸Ü¡A´N¥X°ÝÃD¤F¡C¥Dn¬O¦]¬°¤@¦ý¸ó¤ë¡A¤é´Á´N·|±q1¸¹¶}©l¡A¦bFor Next ¦^°é¸Ì±¨S¿ìªk³B²z¡A§Ú´¿¸g¤]¬OµÛ¥Îblock Ifªº§PÂ_¦¡·Q¥h¤À¿ë¤£¦Pªº±¡ªp¡A¦ý¬O¦n¹³¥ÎIf ¤§«á¨S¿ìªk¥ÎFor ³o¼Ëexcel·|§i¶D§Ú¡§¦³If ¦ý¨S¦³End If"
½Ð°Ý¦³¨S¦³¿ìªk¸Ñ¨M¡]©Î§ï¼g¡^³oÓ°ÝÃD©O¡H ÁÂÁ¦U¦ì
PS: ì©lÀɮצ³ÂI¹L¤j¡AµLªkªþ¥[¡A³Â·Ð¦Ü http://min.us/mx0lbUjTp ¤U¸ü ¡]ÂàÀɳ¡¥÷ªºCode§@ªÌ¬°¡iµ{¦¡¥æ©ö»EÄ_¬Ö¡jªºCLCY¤j¡^ |