Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi there,

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

    I've tryied writing this:

    Code:
    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" error on Word 2000, as the Selection object has no PasteAndFormat method and the On Error statement does help much in this situation...

    Ideally, i would like to test if the object "Selection" has a "PasteAndFormat" method before calling 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?)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can look at Application.Version. This returns a string "9.0" for Word 2000, "10.0" for Word 2002 etc. So for example

    If Val(Application.Version) < 10 Then
    ...
    Else
    ...
    End If

    You can *not* test in runtime whether a method exists - an error handler won't help here.

  3. #3
    New Lounger
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok thank you for the workaround again Hans

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •