Microsoft Wordを操作

Microsoft Wordを読み込んでみようの続き

Imports Microsoft.Office.Core.MsoShapeType

図形なんかを処理したい場合はコイツもインポートしておこう。
以下は分かりやすいようにインポートせずに記載。

For Each wTable As Word.Table In wDoc.Tables 'ドキュメントの表(Tables)の1つを取得
	For Each wCell As Word.Cell In wTable.Range.Cells '表内の1つ(Cell)を取得
		temStr = wCell.Range.Text '値を取得する場合は「Value」ではなく「.Range.Text」
		temStr = wTable.Cell(wCell.RowIndex,  wCell.ColumnIndex + 1).Range.Text 'For Each で指定したセル以外を処理したい場合
	Next
Next
Dim temShape As Word.Shape
For Each temShape In wDoc.Shapes
	If temShape.Type = Microsoft.Office.Core.MsoShapeType.msoTextBox Then '図形の種類がテキストボックスなら
		temStr = temShape.TextFrame.TextRange.Text '値を取得する場合は「Value」ではなく「.TextFrame.TextRange.Text」
	End If
Next