
PowerShellからWordのテキストボックスに文字を入力する方法です。
まず、ワードファイルに一つテキストボックスを貼り付けます。

今回ファイル名は、「TestWordFile.docx」としています。
次にテキストボックスに名前を付けます。

[ホーム]の[編集]から[選択]→[オブジェクトの選択と表示]を選びます。
そして名前を付けます。

今回、「TextBox1」と名前を付けました。
スクリプト
$word = New-Object -ComObject "Word.Application" $word.Visible = $true $word.Documents.Open("C:\work\TestWordFile.docx") $shp = $word.ActiveDocument.Shapes("TextBox1") $shp.TextFrame.TextRange.Text = "あいうえお"
少し解説すると、まず1行目でCOMオブジェクトを作成しています。
そして、4行目でファイルを開き、5行目でShapeオブジェクトを取得し、7行目で文字を入力しています。

結果は、このようになります。
スポンサーリンク