- ©«¤l
- 9
- ¥DÃD
- 2
- ºëµØ
- 0
- ¿n¤À
- 50
- ÂI¦W
- 0
- §@·~¨t²Î
- win7
- ³nÅ骩¥»
- sp1
- ¾\ŪÅv
- 20
- µù¥U®É¶¡
- 2015-9-21
- ³Ì«áµn¿ý
- 2020-7-23
|
¥»©«³Ì«á¥Ñ pipi1968 ©ó 2017-1-5 19:33 ½s¿è
¤w¸Ñ¨M¤F
¤Wºô¬d¤F¦n¤[¡A²×©óOK¤F
´£¨Ñµ¹»Ýnªº¤H°Ñ¦Ò- Function IsFileOpen(strFile As String) As Boolean
- Dim iFile As Integer
- Dim iErr As Integer
-
- On Error Resume Next
- iFile = FreeFile()
- Open strFile For Input Lock Read As #iFile '¥HÂê©w¤è¦¡¶}±Ò¡A¶}±Ò«ü©wÀɮ׫᪽±µÃö³¬ÀÉ®×
- Close iFile
-
- iErr = Err '±N¿ù»~¸¹½X±a¤JiErrÅܼƤ¤¡AµM«á¨Ì·Ó¼Æ¦r§Y¥i±oª¾Àɮת¬ºA
- On Error GoTo 0
- Select Case iErr
- Case 0
- IsFileOpen = False
- Case 70
- IsFileOpen = True
- Case 53
- MsgBox "§ä¤£¨ìÀɮסA±N«Ø¥ßªÅ¥Õ¶i«×ºÞ¨îªí¡I"
- IsFileOpen = False
- Case 76
- MsgBox "§ä¤£¨ì¸ô®|¡A½Ð¦A½T»{¡I"
- IsFileOpen = False
- End Select
- End Function
- Sub CheckFile()
- Dim strPath As String
- Dim strFile As String
- Dim strWordFile As String
- Dim wordDoc As Object
- Set wordApp = CreateObject("Word.Application")
- Set fs = CreateObject("Scripting.FileSystemObject")
-
- strFile = "¥_°Ï1.docx"
- strPath = "D:\My Documents\Temp\"
- strWordFile = strPath & strFile
-
-
- If IsFileOpen(strWordFile) Then
- Set wordDoc = GetObject(strWordFile)
- Application.Visible = True
- GoTo 101
- ElseIf fs.FileExists(strWordFile) Then
- Set wordDoc = wordApp.Documents.Open(strWordFile)
- wordApp.Visible = True
- wordDoc.Activate
- GoTo 101
- Else
- FileCopy strPath & "ªÅ¥Õ®×¥ó¶i«×ºÞ±±ªí.docx", strWordFile
- Set wordDoc = wordApp.Documents.Open(strWordFile)
- wordApp.Visible = True
- wordDoc.Activate
- GoTo 101
- 'MsgBox ("Àɮפ£¦s¦b¡I")
- 'Exit Sub
- End If
-
- 101:
- With wordDoc.Tables(1)
- .Cell(6, 2) = Replace(.Cell(6, 2), Chr(13), "") & "¡B³o¬O´ú¸Õ"
-
- '¨ú±owordªº¤é(®É)¼Æ¡A«·spºâÁ`¤u§@®É¼Æ
- If InStr(.Cell(6, 3), "¤é") = 0 And InStr(.Cell(6, 3), "¤p®É") = 0 Then
- WorkHours = 0
- GoTo 102
- Else
- xString = .Cell(6, 3)
- xtemp = Split(xString, "¤é")
- hours = Val(xtemp(0)) * 8
- xtemp = Split(xtemp(1), "¤p®É")
- WorkHours = hours + Val(xtemp(0))
- End If
- 102:
- '¥[·s¼W®É¼Æ:¹wp¼W¥[4.5¤p®É
- WorkHours = WorkHours + 4.5
- 'pºâ¤é¼Æ(¨C8¤p®É¬°1¤é)
- days = Int(WorkHours / 8)
- 'pºâ³Ñ¾l¤p®É
- hours = WorkHours - days * 8
- '¼g¦^wordªí®æ
- .Cell(6, 3) = days & "¤é" & hours & "¤p®É"
- End With
- 'wordDoc.Close 'Ãö³¬¸ÓWord¤å¥óÀÉ
- 'wordApp.Quit 'µ²§ôWordÀ³¥Îµ{¦¡
- 'Set wordDoc = Nothing 'ÄÀ©ñª«¥óÅܼÆwordDoc
- 'Set wordApp = Nothing 'ÄÀ©ñª«¥óÅܼÆwordApp
- End Sub
½Æ»s¥N½X |
|