Sub tbl()
On Error Resume Next '忽略錯誤
Dim tblcnt As Integer
Dim R As Integer
Dim C As Integer
Dim i As Integer
Dim j As Integer
Dim tbs As Integer
tblcnt = Application.ActiveDocument.Tables.Count
'Debug.Print "tabel有 " & tblcnt & " 個 "
'Debug.Print "tabel一 R 有 " & R & " 個 C 有 " & C & " 個"
Dim S As String
Dim DataS As String
For tbs = 1 To tblcnt
Debug.Print "表格 " & tbs
Debug.Print "-------------------------------------------------------------------------------"
R = Application.ActiveDocument.Tables(tbs).Rows.Count
C = Application.ActiveDocument.Tables(tbs).Columns.Count
For i = 1 To R
DataS = " | "
For j = 1 To C
'Debug.Print Application.ActiveDocument.Tables(1).Cell(i, j).Range.Text
'S = Replace(Application.ActiveDocument.Tables(tbs).Cell(i, j).Range.Text, vbCrLf, "")
'若有些表格被合併時
S = Application.ActiveDocument.Tables(tbs).Cell(i, j).Range.Text
S = Replace(S, vbCr, "")
S = Replace(S, vbLf, "")
If Len(S) = 0 Then
DataS = DataS & " - | "
Else
DataS = DataS & "(" & i & "," & j & ") " & S & " | "
End If
Next
Debug.Print DataS
DataS = ""
Next
Debug.Print vbCrLf
Debug.Print vbCrLf
Next
End Sub
'輸出結果範例
'-----------------------------------------------------------------------------------
表格 1
-------------------------------------------------------------------------------
| (1,1) 1,1 | (1,2) 結束案件數 | (1,3) 7日內報案件數 | (1,4) 未於7日內報案件數 | (1,5) 未案件數 |
| (2,1) 93年 | (2,2) | (2,3) | (2,4) | (2,5) |
| (3,1) 94年 | (3,2) 19 | (3,3) 19 | (3,4) | (3,5) |
| (4,1) 95年 | (4,2) 25 | (4,3) 25 | (4,4) | (4,5) |
| (5,1) 96年 | (5,2) 37 | (5,3) 37 | (5,4) | (5,5) |
| (6,1) 97年 | (6,2) 62 | (6,3) 62 | (6,4) | (6,5) |
| (7,1) 98年 | (7,2) 106 | (7,3) 106 | (7,4) | (7,5) |
| (8,1) 合計 | (8,2) 252 | (8,3) 252 | (8,4) | (8,5) |
表格 2
-------------------------------------------------------------------------------
| (1,1) 各單位 | (1,2) 結束案件數 | (1,3) 7日內報案件數 | (1,4) 未於7日內報案件數 | (1,5) 未報案件數 |
| (2,1) 93年 | (2,2) 2,2 | (2,3) | (2,4) | (2,5) |
| (3,1) 94年 | (3,2) | (3,3) | (3,4) | (3,5) |
| (4,1) 95年 | (4,2) | (4,3) | (4,4) | (4,5) |
| (5,1) 96年 | (5,2) | (5,3) | (5,4) | (5,5) |
| (6,1) 97年 | (6,2) | (6,3) | (6,4) | (6,5) |
| (7,1) 98年 | (7,2) | (7,3) | (7,4) | (7,5) |
| (8,1) 合計 | (8,2) | (8,3) | (8,4) | (8,5) |
沒有留言:
張貼留言