2012年6月7日木曜日

EXCEL:封筒印刷マクロ

久々にエクセルマクロを作成した。
やっぱり落ち着く。

次のOfficeからVBAが消えちゃうみたいだけど。。。
はぁ~、これからどうしよう。
更に就職難。

Sub Main
   '-----------------------------------------------------------
   '  関数名:
   ' 引数
 
   ' 戻り値
 

 '    
  '-----------------------------------------------------------

 For n = a To b
        If Sheets("住所録").Cells(Row, 4) = "封筒1" Then
            Sheets("封筒1").Select
            ''郵便番号
            Sheets("封筒1").Cells(13, 1) = Sheets("住所録").Cells(Row, 6)
            ''都道府県+住所1
            Sheets("封筒1").Cells(15, 1) = Sheets("住所録").Cells(Row, 7) & Sheets("住所録").Cells(Row, 8)
            ''住所2
            Sheets("封筒1").Cells(18, 1) = Sheets("住所録").Cells(Row, 9)
            ''名前
            Sheets("封筒1").Cells(21, 1) = Sheets("住所録").Cells(Row, 5) & " 様"
            ActiveSheet.PrintPreview
             Sheets("封筒1").Cells(13, 1) = ""
             Sheets("封筒1").Cells(15, 1) = ""
             Sheets("封筒1").Cells(18, 1) = ""
             Sheets("封筒1").Cells(21, 1) = ""
   
     ElseIf Sheets("住所録").Cells(Row, 4) = "封筒2" Then
             Sheets("封筒2").Select
            ''郵便番号

            Sheets("封筒2").Cells(13, 1) = Sheets("住所録").Cells(Row, 6)
            ''都道府県+住所1
            Sheets("封筒2").Cells(15, 1) = Sheets("住所録").Cells(Row, 7) & Sheets("住所録").Cells(Row, 8)
            ''住所2
            Sheets("封筒2").Cells(18, 1) = Sheets("住所録").Cells(Row, 9)
            ''名前
            Sheets("封筒2").Cells(21, 1) = Sheets("住所録").Cells(Row, 5) & " 様"
            ActiveSheet.PrintPreview
            '--------------------------------------------------------------------
            ' clear
            '--------------------------------------------------------------------
             Sheets("封筒2").Cells(13, 1) = ""
             Sheets("封筒2").Cells(15, 1) = ""
             Sheets("封筒2").Cells(18, 1) = ""
             Sheets("封筒2").Cells(21, 1) = ""
        ElseIf Sheets("住所録").Cells(Row, 4) = "封筒3" Then
             Sheets("封筒3").Select
            ''郵便番号

            Sheets("封筒3").Cells(13, 1) = Sheets("住所録").Cells(Row, 6)
            ''都道府県+住所1
            Sheets("封筒3").Cells(15, 1) = Sheets("住所録").Cells(Row, 7) & Sheets("住所録").Cells(Row, 8)
            ''住所2
            Sheets("封筒3").Cells(18, 1) = Sheets("住所録").Cells(Row, 9)
            ''所属1
            Sheets("封筒3").Cells(21, 1) = Sheets("住所録").Cells(Row, 10)
            ''所属2
            Sheets("封筒3").Cells(22, 1) = Sheets("住所録").Cells(Row, 11)
            ''所属3
            Sheets("封筒3").Cells(23, 1) = Sheets("住所録").Cells(Row, 12)
           
            ''名前
            Sheets("封筒3").Cells(24, 1) = Sheets("住所録").Cells(Row, 5) & " 様"
            ActiveSheet.PrintPreview
            '--------------------------------------------------------------------
            ' clear
            '--------------------------------------------------------------------
             Sheets("封筒3").Cells(13, 1) = ""

             Sheets("封筒3").Cells(15, 1) = ""
             Sheets("封筒3").Cells(18, 1) = ""
             Sheets("封筒3").Cells(21, 1) = ""
             Sheets("封筒3").Cells(22, 1) = ""
             Sheets("封筒3").Cells(23, 1) = ""
             Sheets("封筒3").Cells(24, 1) = ""
        Else
            MsgBox ("封筒が選択されていません。")
        End If
        Row = Row + 1
   
    Next
    Sheets("住所録").Select

0 件のコメント:

コメントを投稿