[[20141016172111]] 『印刷』(soumu) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『印刷』(soumu)

EXCELファイルで「現在のページを印刷」「カーソルのあるページを印刷」
という設定をしたいのですが、
そういった機能がWORDにしかありません。
EXCELでも同じような事ができますでしょうか?

< 使用 Excel:Excel2007、使用 OS:Windows7 >


たぶんマクロを使うことになるのでは。

 Sub test()
    Dim i As Long
    Dim r As Long, c As Long
    Dim myY As Long, myX As Long
    Dim p As Long
    ActiveWindow.View = xlPageBreakPreview

    r = ActiveCell.Row
    c = ActiveCell.Column

    With ActiveSheet
        myY = 1
        If .HPageBreaks.Count > 0 Then
            For i = 1 To .HPageBreaks.Count
                If r < .HPageBreaks(i).Location.Row Then Exit For
                myY = myY + 1
            Next
        End If
        myX = 1
        If .VPageBreaks.Count > 0 Then
            For i = 1 To .VPageBreaks.Count
                If c < .VPageBreaks(i).Location.Column Then Exit For
                myX = myX + 1
            Next
        End If

        If .PageSetup.Order = xlDownThenOver Then
            p = (.HPageBreaks.Count + 1) * (myX - 1) + myY
        Else
            p = (.VPageBreaks.Count + 1) * (myY - 1) + myX
        End If

        .PrintOut From:=p, To:=p

    End With

    ActiveWindow.View = xlNormalView

 End Sub

(マナ) 2014/10/16(木) 19:35


本当にありがとうございます!!

スゴイです(>_<)
思っていた事が完璧にできました!!
感謝しております。。
ありがとうございます。

これで仕事がはかどりそうです!!!!
(soumu) 2014/10/16(木) 19:42


もう一つワガママを言わせて下さい。。
教えてもらっておきながら厚かましいのですが。。。

上記のマクロで印刷をかけた所「表示/改ページ」プレビューが「標準」になってしまうんです。
修正ができるようであればご教授願います。

私は全くのマクロ初心者です。
申し訳ございません。
(soumu) 2014/10/16(木) 19:54


ActiveWindow.Viewで表示状態を切り替えられます。
こんな感じです。

 Sub test2()
    Dim v As Long
    Dim i As Long
    Dim r As Long, c As Long
    Dim myY As Long, myX As Long
    Dim p As Long

    v = ActiveWindow.View                   '★現在の表示
    ActiveWindow.View = xlPageBreakPreview  '★改ページに変更

    r = ActiveCell.Row
    c = ActiveCell.Column

    With ActiveSheet
        myY = 1
        If .HPageBreaks.Count > 0 Then
            For i = 1 To .HPageBreaks.Count
                If r < .HPageBreaks(i).Location.Row Then Exit For
                myY = myY + 1
            Next
        End If
        myX = 1
        If .VPageBreaks.Count > 0 Then
            For i = 1 To .VPageBreaks.Count
                If c < .VPageBreaks(i).Location.Column Then Exit For
                myX = myX + 1
            Next
        End If

        If .PageSetup.Order = xlDownThenOver Then
            p = (.HPageBreaks.Count + 1) * (myX - 1) + myY
        Else
            p = (.VPageBreaks.Count + 1) * (myY - 1) + myX
        End If

        .PrintOut From:=p, To:=p

    End With

    ActiveWindow.View = v       '★元の表示に戻す

 End Sub

(マナ) 2014/10/16(木) 20:24


ご丁寧に教えて頂いてありがとうございます。
本当に助かりました!!

(soumu) 2014/10/17(金) 14:37


コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.