-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableOps.bas
70 lines (64 loc) · 2.25 KB
/
TableOps.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Attribute VB_Name = "TableOps"
Option Explicit
Option Explicit
Sub splitTableByEachRow()
Dim r As Long, cel As Cell, s As Long, e As Long, s1 As Long, e1 As Long, rng As Range
Dim inlsp As InlineShape
r = 1
With Selection
Set rng = .Range
Do While (.Information(wdWithInTable))
.SplitTable
Set cel = Selection.Document.Tables(r).Cell(1, 8)
If cel.Range.InlineShapes.Count > 0 Then
Else
If Selection.Document.Tables(r).Rows.Count > 1 Then _
Set cel = Selection.Document.Tables(r).Cell(2, 8)
End If
s = .Start: e = .End
rng.SetRange s, s
If cel.Range.InlineShapes.Count > 0 Then
cel.Range.InlineShapes(1).Select
.Cut
' cel.Range.InlineShapes(1).Range.Cut ' 若要用Range則記得要DoEvents讓系統剪貼簿完成工作
' DoEvents'或許剛開始還行,久了還是會出錯。還是用Selection物件才保險、萬無一失
s1 = .Start: e1 = .End
If s1 > s Then
Do While (rng.Information(wdWithInTable))
s1 = s1 - 1
rng.SetRange s1, s1
Loop
ElseIf s1 < s Then
Do While (rng.Information(wdWithInTable))
s1 = s1 + 1
rng.SetRange s1, s1
Loop
End If
rng.Select
.Paste
If .Previous.InlineShapes.Count > 0 Then
With .Previous.InlineShapes(1)
.LockAspectRatio = msoTrue
.Height = 200
End With
Else
.MoveRight wdCharacter, 1, wdExtend
With .InlineShapes(1)
'.LockAspectRatio = msoTrue
.Height = .Height + 181
.Width = .Width + 181
End With
End If
.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Document.Tables(r).Columns(8).Cells.Delete
End If
r = r + 1
If Selection.Document.Tables(r).Rows.Count > 1 Then
Selection.Document.Tables(r).Rows(2).Select
Else
Exit Do
End If
Loop
End With
Beep
End Sub