Skip to content

Instantly share code, notes, and snippets.

@Nia-TN1012
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nia-TN1012/0f746d7d0a293a7c2230 to your computer and use it in GitHub Desktop.
Save Nia-TN1012/0f746d7d0a293a7c2230 to your computer and use it in GitHub Desktop.
Word用のVBAで俳句を出力するプログラムを作ってみました。

このGistに上がっているVBAソースファイルの概要

  • Haiku-word.vb : Ver. 1.0, Wordの文章に俳句を縦書きで出力するモジュールです。
  • Haiku-word2.vb : Ver. 1.1, 俳句を縦書きのテキストボックスに出力するモジュールです。
  • Haiku-word3.vb : Ver. 1.2, Wordの文章に、ユーザーフォームから入力した任意の俳句を縦書きで出力するモジュールです。
' Auther : Nia Tomonaka
' Twitter : https://twitter.com/nia_tn1012
Option Explicit
Sub Haiku()
With ActiveDocument.Content
' vbCrLfは改行記号です。
.Text = "初桜" + vbCrLf + "折しも今日は" + vbCrLf + "よき日なり"
' フォントを行書体にします。
.Font.name = "HGS行書体"
.Font.Size = "30"
' 文字方向を縦書きにします。
.Orientation = wdTextOrientationVerticalFarEast
End With
End Sub
' Haiku-word.vb ( WordのVBA用 )
' Copyright (c) 2014-2015 Myoga-TN.net All Rights Reserved.
' This software is released under the MIT License.
' http://opensource.org/licenses/mit-license.php
' Auther : Nia Tomonaka
' Twitter : https://twitter.com/nia_tn1012
Option Explicit
Sub Haiku()
' 縦書きのテキストボックスを作成します。
' ActiveDocument.PageSetupのLeftMarginとTopMarginで、印刷領域の左上の位置を取得します。
ActiveDocument.Shapes.AddTextbox( _
msoTextOrientationVerticalFarEast, _
ActiveDocument.PageSetup.LeftMargin, _
ActiveDocument.PageSetup.TopMargin, _
180, 300) _
.Select
' テキストボックスに文字列とフォントを設定します。
With Selection
.Text = "初桜" + vbCrLf + "折しも今日は" + vbCrLf + "よき日なり"
.Font.name = "HGS行書体"
.Font.Size = "30"
End With
End Sub
' Haiku-word3.vb ( WordのVBA用 )
' Copyright (c) 2014-2015 Myoga-TN.net All Rights Reserved.
' This software is released under the MIT License.
' http://opensource.org/licenses/mit-license.php
' Auther : Nia Tomonaka
' Twitter : https://twitter.com/nia_tn1012
' ユーザーフォーム(HaikuRegister)にテキストボックス
' (Phrase1、Phrase2、Phrase3)を用意し、そこに俳句を入力します。
' 俳句を生成するボタンを押すとこのイベントが呼び出されます。
Private Sub Register_Click()
With ActiveDocument.Content
' vbCrLfは改行記号です。
.Text = Phrase1.Text + vbCrLf + Phrase2.Text + vbCrLf + Phrase3.Text
' フォントを行書体にします。
.Font.name = "HGS行書体"
.Font.Size = "30"
' 文字方向を縦書きにします。
.Orientation = wdTextOrientationVerticalFarEast
End With
Unload HaikuRegister
End Sub
' Haiku-word2.vb ( WordのVBA用 )
' Copyright (c) 2014-2015 Myoga-TN.net All Rights Reserved.
' This software is released under the MIT License.
' http://opensource.org/licenses/mit-license.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment