'konggs兄的方法甚妙,不过老兄好象没有调试啊,有点小问题,在你代码的基础上我稍做修改,老兄莫怪。 Sub SelectCustomPage() Dim mypages Dim arr1 On Error Resume Next mypages = InputBox("输入页数,与打印一样,间隔用短号,连续用-", "konggs", "1") '得到输入的内容 '判断是否合法 If Not IsNumeric(Replace(Replace(mypages, ",", ""), "-", "")) Then If mypages = "" Then MsgBox "你按下了取消或没输入任何内容", 64 + 1, "konggs" Else MsgBox "此输入有非法字法", 64 + 1, "konggs": Exit Sub End If End If '得到各个对应的页数 mypages = myallpages(mypages, ActiveDocument.Range.Information(wdActiveEndPageNumber)) '若用ThisDocument则只能把宏放在当前文档中了(不能放入模板中) Application.ScreenUpdating = False '预防性删除 ActiveDocument.DeleteAllEditableRanges wdEditorEveryone '把每页的区域添加到编辑区 For Each arr1 In mypages Selection.GoTo What:=wdGoToPage, Count:=arr1 ActiveDocument.Bookmarks("\Page").Range.Editors.Add (wdEditorEveryone) Next '选中所有的编辑区 ActiveDocument.SelectAllEditableRanges wdEditorEveryone ActiveDocument.DeleteAllEditableRanges wdEditorEveryone Application.ScreenUpdating = True End Sub Function myallpages(mypages, numpage) Dim arr1, temparr1 Dim arr2 arr1 = Split(mypages, ",") ReDim arr2(0) Dim findint%, j%, i% For Each temparr1 In arr1 findint = InStr(1, temparr1, "-") If findint > 0 Then For j = Mid(temparr1, 1, findint - 1) To Mid(temparr1, findint + 1, Len(temparr1) - findint) If j > numpage Then '如果输入的数字大于总数则跳出循环,否则会影响速度 Exit For End If ReDim Preserve arr2(i) arr2(i) = j i = i + 1 Next Else ReDim Preserve arr2(i) arr2(i) = CInt(temparr1) i = i + 1 End If Next myallpages = arr2 End Function
[此贴子已经被作者于2007-4-23 17:54:38编辑过] |