5491 application-defined or object-defined error

all,

 

this code below fails on the one computer it needs to work on, no matter how i call it.  i am calling from Access.  also it doesnt matter if i remove dim LT and use List instead:

Sub bulletFormat()
Selection.HomeKey wdStory
Dim doc As Word.Document
Set doc = ActiveDocument
Dim LT As List
    For Each LT In ActiveDocument.Lists ' this line errors
        LT.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
        ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _
        False, ApplyTo:=wdListApplyToSelection, DefaultListBehavior:= _
        wdWord10ListBehavior
        Next
End Sub

 

Tighe

Answer
Answer

doug,

 

thanks for the advice.  i checked the references and they were the same.  both computers are using the same version of office.  i have to admit, as self taught, i am not familiar enough with early/late binding to know which i am using.

 

here where it gets wierd.  i changed the way it was being called from Access but if failed about half of the time, so i added error handling on the code in word, that was failing.  first adding a msgbox, just to warn that the bullets had not been formatted, but after i did this they always were formatted, so i changed the erorr handling to Resume Next.  it now works everytime, ran through it about 20 times, with no issues.

 

so here is the final working code:

Sub bulletFormat()
On Error GoTo Bullet_Error
Selection.HomeKey wdStory
Dim doc As Word.Document
Set doc = ActiveDocument
Dim LT As List
    For Each LT In doc.Lists
        LT.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
        ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _
        False, ApplyTo:=wdListApplyToSelection, DefaultListBehavior:= _
        wdWord10ListBehavior
        Next
Bullet_Error:
Resume Next
End Sub

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 649 Applies to: