1

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
4

1 に答える 1

2

ListGalleries は、Word アプリケーション内のオブジェクトです。アクセスするには、wrdApp.ListGalleries を使用する必要がありました。コードの固定行を以下に示します。

thisRange.ListFormat.ApplyListTemplate ListTemplate:=wrdApp.ListGalleries(wdBulletGallery).ListTemplates(1)
于 2012-07-13T15:50:25.863 に答える