I am trying to use VBA code in Excel to create a numbered list in a Word document.
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
When I run this I get an error:
Method 'ApplyListTemplateWithLevel' of object 'ListFormat' failed
I have checked the Microsoft Word 12.0 Object Library
in the Excel VBA references list.
DoEvents
for the line which is causing the error? – Siddharth Rout