How to test if an object supports a method in Word VB

G

gfox

Hi,

I'm trying to write a macro that is compatible with Word 2000+ that paste
some text matching the surrounding formatting, or simply paste as HTML if
Word does not support this feature.

I've tryied writing this:

Sub PasteAndFormat()
On Error GoTo error
Selection.PasteAndFormat (wdFormatSurroundingFormattingWithEmphasis)
error:
' If error, simply paste it as HTML
Call PasteAsHTML
End Sub

which triggers a "Method or data member not found" on Word 2000, as the
Selection object has no PasteAndFormat method and the On Error statement does
not provide much help in this case.

Ideally, i would like to test if the object "Selection" has a
"PasteAndFormat" method before trying to call it...

How would you do this?
(is there any workaroud to detect the version of Word, so i would not try to
execute this code if my client has got Word 2000?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top