|
綀習寫的,做法笨手笨腳,就參考看看吧~
輸入頁數的時候,請輸入一頁,回車,再輸入下一頁…
目前設定一次最多刪15頁。
不過,您提供的文檔會出錯,因為有表格跨頁…
目前測出來,若跨頁前後是文字,應該就沒有問題。
====
Sub 巨集1()
'
' 巨集1 巨集
' 巨集錄製於 2012/12/4 Tuesday,錄製者 sol
Application.ScreenUpdating = False
max = Selection.Information(wdNumberOfPagesInDocument)
Dim pages(1 To 15) As Integer
x = 1
y = 0
msg = "欲刪除頁數:"
Do While x < 15
inputagain:
pages(x) = InputBox(msg & vbCrLf & vbCrLf & "請輸入欲刪除頁數,一次輸入一頁。" & vbCrLf & _
"結束輸入請按「取消」,或留空按「確認」即可。" & vbCrLf & _
vbCrLf & "本文檔僅" & max & "頁,請勿超出此頁數。")
On Error GoTo error
'Resume
If pages(x) > max Then
MsgBox ("別逗了,沒那麼多頁啦!再來一次!")
GoTo inputagain
End If
msg = msg & pages(x) & "、"
x = x + 1
y = y + 1
Loop
error:
For j = 1 To y
For i = 1 To y
If pages(i) < pages(i + 1) Then
z = pages(i)
pages(i) = pages(i + 1)
pages(i + 1) = z
End If
Next i
Next j
x = 1
Do While x <= y
If pages(x) = max Then
Selection.EndKey Unit:=wdStory
Else
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=pages(x) + 1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
End If
Selection.InsertAfter "卍"
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=pages(x)
Selection.InsertAfter "卍"
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Do While Selection.Next <> "卍"
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Loop
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Delete
x = x + 1
Loop
Application.ScreenUpdating = False
End Sub
|
|