我想在Excel中使用VBA代碼在Word文檔中創建編號列表。用於在Word中創建編號列表的Excel VBA
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 = 0 To 5
.Content.InsertAfter ("Paragraph " & i)
.Content.InsertParagraphAfter
Next
.Paragraphs(1).Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdNumberGallery).ListTemplates(1), ContinuePreviousList:= _
False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
End With
Set wrdApp = Nothing
Set wrdDoc = Nothing
當我運行此我得到一個錯誤:
Method 'ApplyListTemplateWithLevel' of object 'ListFormat' failed
我在Excel VBA中的引用列表檢查Microsoft Word 12.0 Object Library
。
我測試的代碼在Excel 2010中的Word 2010.它完美...測試它於2007年 – 2012-04-26 08:43:46
該死! VMWare上的我的Vista正在配置更新。我需要一些時間才能測試上述內容...... – 2012-04-26 08:50:37
最後在Office 2007中進行了測試。它工作得很好。 – 2012-04-26 09:29:27