Originally Posted by
Howard Kaikow
I suddenly have encountered a problem using the Clearformatting method via a Word object in a VB 6 DLL.
So, I tried to reproduce the behavior within Word itself, and was able to do so.
The first sub below results in an error, the second does not.
Can anybody reproduce this problem?
In which version of Word?
[vba]
Option Explicit
Private Sub TestClearFormattingAutomation()
Dim x As Word.Application
Set x = New Word.Application
With x
.Documents.Add
With .ActiveDocument.Content.Find
On Error Resume Next
.ClearFormatting
Debug.Print Err.Number, Err.Description
Err.Clear
End With
.ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End With
x.quit
Set x = nothing
End Sub
Private Sub TestClearFormattingNoAutomation()
With Application
.Documents.Add
With .ActiveDocument.Content.Find
On Error Resume Next
.ClearFormatting
Debug.Print Err.Number, Err.Description
Err.Clear
End With
.ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End With
End Sub
[/vba]