|
第一页 有按钮,按钮是图片,所以第一页永远会输出,除非把按钮删除!或者从第二页(或者第三页,或者第N页。。。。)开始提取!
详见代码:
- Private Sub CommandButton1_Click()
- ' 输出只需要彩色打印的页码至txt文本,以便降低打印成本!
- Dim rng As Range, d As Object, Act As Document, k, i%, oSt%
- Dim oRang As Range, oPara As Paragraph, mt, t, s, m, n, oEt%
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set Act = ActiveDocument
- oEt = Act.ActiveWindow.ActivePane.Pages.Count
- oSt = InputBox("输入开始页码", , "1")
- If oSt = oEt Then Exit Sub
- For i = oSt To oEt
- Set rng = Selection.GoTo(1, 1, i).Bookmarks("\page").Range
- If rng.InlineShapes.Count + rng.ShapeRange.Count > 0 Then
- d(i) = "": GoTo 100
- Else
- With CreateObject("VBScript.Regexp")
- .Global = True: .Pattern = "[^\x07\s\u3000\0a\x0b]"
- For Each oPara In rng.Paragraphs
- For Each mt In .Execute(oPara.Range.Text)
- m = mt.FirstIndex: n = mt.Length
- Set oRang = ActiveDocument.Range(oPara.Range.Start + m, oPara.Range.Start + m + n)
- clo = oRang.Font.ColorIndex: gls = oRang.HighlightColorIndex
- If gls <> 0 Or (clo <> 0 And clo <> 1 And clo <> 8 And clo <> 9999999) Then
- d(i) = "": GoTo 100
- End If
- Next
- Next
- End With
- End If
- 100 Next
- t = d.keys
- For i = 0 To d.Count - 1
- If i = 0 Then
- s = t(0)
- Else
- If t(i) - t(i - 1) = 1 Then
- s = s & "|" & t(i)
- Else
- s = s & "," & t(i)
- End If
- End If
- Next
- With CreateObject("VBScript.Regexp")
- .Global = True: .Pattern = "\|[|\d]+\|"
- s = Replace(.Replace(s, "-"), "|", "-")
- End With
- Open Act.Path & "\页码.txt" For Output As #1
- Print #1, "需要彩打的页码为:" & vbCrLf & s
- Close #1
- Application.ScreenUpdating = True
- MsgBox "页码已输出到同文件夹下的TXT文本!"
- End Sub
复制代码 |
|