Word用のVBA テキストファイルからテキストボックスを吐き出すマクロ
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
動作見本
Author And Source
この問題について(Word用のVBA テキストファイルからテキストボックスを吐き出すマクロ), 我々は、より多くの情報をここで見つけました https://qiita.com/seastar3/items/a6b5002fa1ba3026bf90著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .