首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >应用ListTemplate后MS Word崩溃

应用ListTemplate后MS Word崩溃
EN

Stack Overflow用户
提问于 2012-07-13 14:05:02
回答 1查看 1.4K关注 0票数 1

我使用Excel2010VBA以编程方式生成Word 2010文档。

当我试图将ListTemplate应用于我插入的段落之一时,程序就会崩溃(下面代码中的第5行)。

代码语言:javascript
运行
复制
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)“ 自动化误差 远程过程调用失败。

整个程序:

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-13 15:50:25

ListGalleries是Word Application中的一个对象。要访问它,我需要使用wrdApp.ListGalleries。固定代码行如下所示。

代码语言:javascript
运行
复制
thisRange.ListFormat.ApplyListTemplate ListTemplate:=wrdApp.ListGalleries(wdBulletGallery).ListTemplates(1)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11472074

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档