#contents

*Excel 関連情報 [#h16c0d62]
**サンプルコード [#xf07e57e]
***ページヘッダのページ番号を「0詰め」して印刷する方法 [#v38774bb]
-ページヘッダのページ番号を「0詰め」して印刷する方法
 ' <使い方>
 ' 1. Excel の「Visual Basic Editor」を起動します。
 ' 2. [挿入] - [標準モジュール] を選択します。
 ' 3. 下記のコードを貼り付けます
 ' 4. [実行] - [Sub/ユーザー フォームの実行] で
 '    SpecialPrint() プロシージャを実行します。
 '    → ページヘッダのページ番号が「0詰め」されて印刷されます
 Option Explicit
 
 ' シート内のページ数を算出
 ' <参考サイト>
 ' [XL2002] 印刷されるページの総数を調べる方法
 ' http://support.microsoft.com/kb/408042/ja
 Function GetPageCount(ByRef ws As Worksheet) As Integer
     Dim H_Break As Integer
     Dim V_Break As Integer
     Dim P_Page As Integer
     Dim A_Cell As String
     A_Cell = ws.UsedRange.Address       '最後のセルのアドレスを取得
     If A_Cell = "$A$1" Then
         If IsEmpty(ws.Range(A_Cell).Value) Then
             MsgBox "印刷するデータはありません。"
             Exit Function
         End If
     End If
     H_Break = ws.HPageBreaks.Count    '横の改ページ数取得
     V_Break = ws.VPageBreaks.Count    '縦の改ページ数取得
     If V_Break = 0 Then
         P_Page = H_Break + 1
     Else
       H_Break = H_Break + 1
       V_Break = V_Break + 1
       P_Page = H_Break * V_Break
     End If
     GetPageCount = P_Page
 End Function
 
 ' 特殊印刷処理
 Sub SpecialPrint()
     Dim n As Integer
     Dim nCount As Integer
     Dim wb As Workbook
     Dim ws As Worksheet
     For Each wb In Workbooks
       For Each ws In wb.Worksheets
         ' シートのページ数を取得
         nCount = GetPageCount(ws)
         ' ページ数ぶんループ
         For n = 1 To nCount
             ' 中央ヘッダに「0詰め」した「ページ番号」を表示
             ws.PageSetup.CenterFooter = Format(n, "00")
             ' 指定ページを印刷(nページ目〜nページ目を印刷)
             ws.PrintOut n, n, 1
         Next
       Next
     Next
 End Sub

-はてな
--http://www.hatena.ne.jp/1106800333

-参考情報
--ヘッダー/フッダーを設定する
---http://www2.moug.net/cgi-bin/technic.cgi?exvba+TI07010013
---http://www.moug.net/skillup/nksw/nksw05-03.htm?PRINT
--印刷時、フッターにブック名とシート数を総ページ数としたページ番号を入れる
---http://www2.moug.net/cgi-bin/technic.cgi?exvba+TI07010007
--Excelノート 9-1 印刷
---http://park11.wakwak.com/~miko/Excel_Note/09-01_insatu.htm
--[XL2002]ヘッダー、フッターのページ数に加算、減算すると正しくない
---http://support.microsoft.com/kb/418486/ja
--[XL2002] 印刷されるページの総数を調べる方法
---http://support.microsoft.com/kb/408042/ja

#comment
//#comment


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS