??? Office 2007新的文件格式采用了基于XML的文件格式,新的Office Open XML格式的核心使用一些XML的引用架构和一个ZIP容器,其实就是一个ZIP压缩包。所以我们可以用压缩软件(如WinRAR)打开它,然后通过添加、修改其中文件的方法实现自定义功能区的目的。上面的customUI文件夹必须放入其中才能起作用,另外还必须修改其中“_rels”文件夹中的“.res”文件进行关联,具体步骤如下:
Sub TwoSidePrint(control As IRibbonControl)? '双面打印 ??? On Error Resume Next ??? Dim TotalPageNums As Integer, i As Integer, j As Integer ??? TotalPageNums = ExecuteExcel4Macro("Get.Document(50)") ??? If (TotalPageNums = 0) Then '如果为零,说明没有可打印内容,退出程序 ??? MsgBox "Microsoft Excel 未发现任何可以打印的内容", 0 + 48 ????? Exit Sub ??? End If ??? If TotalPageNums = 1 Then ??????? ActiveSheet.PrintOut ??????? If Err.Number = 1004 Then ??????????? MsgBox "打印时发生错误,请检查打印机设置", 0 + 48 '提示用户发生打印错误 ??????? End If ??????? Exit Sub ??? End If ??? For j = Int(TotalPageNums / 2) + 1 To 1 Step -1 ??? ActiveWindow.SelectedSheets.PrintOut From:=2 * j, To:=2 * j ??? Next j ??? MsgBox "第一面打印完毕后,请将打印出的纸张全部取出," & vbCrLf & vbCrLf & "将出纸方向变为进纸方向放入纸槽中," & vbCrLf & vbCrLf & "单击“确定”,打印另一面。", vbOKOnly, "打印另一面" ??? For i = 1 To Int(TotalPageNums / 2) + 1 ??????? ActiveWindow.SelectedSheets.PrintOut From:=2 * i - 1, To:=2 * i - 1 ??????? If Err.Number = 1004 Then ??????????? MsgBox "打印时发生错误,请检查打印机设置", 0 + 48 '提示用户发生打印错误 ??????????? Exit Sub ??????? End If ??? Next i ??? End Sub
Sub OddPagePrint(control As IRibbonControl)? '打印奇数页 ??? On Error Resume Next ??? Dim TotalPageNums, i As Integer ??? TotalPageNums = ExecuteExcel4Macro("Get.Document(50)") ??? If (TotalPageNums = 0) Then '如果为零,说明没有可打印内容,退出程序 ??????? MsgBox "Microsoft Excel 未发现任何可以打印的内容", 0 + 48 ??????? Exit Sub ??? End If ??? For i = 1 To Int(TotalPageNums / 2) + 1 ??????? ActiveWindow.SelectedSheets.PrintOut From:=2 * i - 1, To:=2 * i - 1 ??????? If Err.Number = 1004 Then ??????????? MsgBox "打印时发生错误,请检查打印机设置", 0 + 48 '提示用户发生打印错误 ??????????? Exit Sub ??????? End If ??? Next i End Sub Sub EvenPagePrint(control As IRibbonControl)? '打印偶数页 ??? On Error Resume Next ??? Dim TotalPageNums As Integer, i As Integer ??? TotalPageNums = ExecuteExcel4Macro("Get.Document(50)") ??? If TotalPageNums = 0 Then '如果为零,说明没有可打印内容,退出程序 ??????? MsgBox "Microsoft Excel 未发现任何可以打印的内容", 0 + 48 ??????? Exit Sub ??? End If ??? If TotalPageNums = 1 Then ??????? MsgBox ("只有第一页!!!") ??????? End ??? End If ??? For i = 1 To Int(TotalPageNums / 2) + 1 ??????? ActiveWindow.SelectedSheets.PrintOut From:=2 * i, To:=2 * i ??????? If Err.Number = 1004 Then ??????????? MsgBox "打印时发生错误,请检查打印机设置", 0 + 48 '提示用户发生打印错误 ??????????? Exit Sub ??????? End If ??? Next i End Sub Sub CurrentPagePrint(control As IRibbonControl) ??? On Error Resume Next ??? Dim m As Integer, n As Integer ??? Dim vPageBreaksCount As Integer, hPageBreaksCount As Integer ??? Dim NumPage As Integer, TotalPages As Integer ??? TotalPages = ExecuteExcel4Macro("Get.Document(50)")? '总的打印页数 ??? If TotalPages = 0 Then ?????? MsgBox "Microsoft Excel 未发现任何可以打印的内容", 0 + 48 ?????? Exit Sub ??? End If ??? hPageBreaksCount = ActiveSheet.HPageBreaks.Count?? '返回水平分页符个数 ??? vPageBreaksCount = ActiveSheet.VPageBreaks.Count?? '返回垂直分页符个数 ??? For n = 1 To hPageBreaksCount? 'n返回当前水平分页符的数量 ??????? If ActiveSheet.HPageBreaks(n).Location.Row > ActiveCell.Row Then Exit For ??? Next ??? For m = 1 To vPageBreaksCount? 'm返回当前垂直分页符的数量 ?????? If ActiveSheet.VPageBreaks(m).Location.Column > ActiveCell.Column Then Exit For ??? Next ??? If ActiveSheet.PageSetup.Order = xlOverThenDown Then? '按页面设置中的打印顺序确定当前单元格所处的页数 ??????? NumPage = (n - 1) * (vPageBreaksCount + 1) + m??? '先行后列 ??? Else ??????? NumPage = (m - 1) * (hPageBreaksCount + 1) + n??? '先列后行 ??? End If ??? ??? '判断选定的单元格是否在打印区域中 ??? If ActiveCell.Value = "" Then? '如果选定的单元格为空 ??????? ActiveCell.Value = 1?????? '给活动单元格赋予临时数值 ??????? If ExecuteExcel4Macro("Get.Document(50)") > TotalPages Or NumPage > TotalPages Then '如果总的打印页数增多或单元格所处页数大于打印页数 ??????????? ActiveCell.Value = "" ??????????? MsgBox "选定的单元格不在打印范围以内!" ??????????? Exit Sub ??????? Else ??????????? ActiveCell.Value = "" ??????????? ActiveSheet.PrintOut From:=NumPage, To:=NumPage, Copies:=1 ??????????? If Err.Number = 1004 Then ??????????? MsgBox "打印时发生错误,请检查打印机设置", 0 + 48 '提示用户发生打印错误 ??????????? Exit Sub ??????? End If ??????????? Exit Sub ??????? End If ??? Else ??????? ActiveSheet.PrintOut From:=NumPage, To:=NumPage, Copies:=1 ??????? If Err.Number = 1004 Then ??????????? MsgBox "打印时发生错误,请检查打印机设置", 0 + 48 '提示用户发生打印错误 ??????????? Exit Sub ??????? End If ??? End If End Sub