LoginSignup
0
1

More than 5 years have passed since last update.

Word用のVBA テキストファイルからテキストボックスを吐き出すマクロ

Last updated at Posted at 2017-08-31

10年ほど前に書いた多数のテキストボックスを吐き出すVBAマクロです。
全国の大学一覧を地図上に置きたくて作りました。
このマクロを持つワードドキュメントと同じフォルダに置いた"chartdata1.txt"ファイルの1行ずつのテキストボックスを最後の行まで吐き出します。
A4縦のレイアウトでつまみやすいようにずらしながらテキストボックスを配置するように作っています。
大量にテキストボックスが必要なときに参考にしてみて下さい。

CommandButton1_Click()
Private Sub CommandButton1_Click()
    Dim i, j, y As Integer
    Dim strTxt As String
    Dim strInRec As String
    Open ActiveDocument.Path & Application.PathSeparator & "chartdata1.txt" For Input As #1
    strTxt = ""
    i = 1
    y = 100
    Do While Not EOF(1)
        i = i + 1
        Line Input #1, strInRec
'        Debug.Print i, strInRec
        strTxt = strInRec
        ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 10 + 20 * Int((i) Mod 14), y + 10 * i, _
        150, 20).Select
        Selection.ShapeRange.TextFrame.TextRange.Select
        Selection.Collapse
        Selection.TypeText Text:=strTxt
    Loop
Close #1
End Sub

動作見本

WordVBA01.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1