Excel 2010 VBA を使用して、Word 2010 ドキュメントをプログラムで生成しています。
挿入した段落の 1 つに ListTemplate を適用しようとすると、プログラムがクラッシュします (以下のコードの 5 行目)。
thisValue = tempSheet.Cells(i, 1).Value
.Content.InsertAfter thisValue
.Content.InsertParagraphAfter
Set thisRange = .Paragraphs(i).Range
thisRange.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(1)
スローされるエラーを以下に示します。
実行時エラー "-2147023170 (800706be)"
オートメーション エラー
リモート プロシージャ コールに失敗しました。
全体の手順:
Sub MoveDataToWord(ByRef tempSheet As Worksheet)
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add
With wrdDoc
For i = 1 To tempSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
thisValue = tempSheet.Cells(i, 1).Value
.Content.InsertAfter thisValue
.Content.InsertParagraphAfter
Set thisRange = .Paragraphs(i).Range
thisRange.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(1)
Next i
End With
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub