• Why Range.Delete failed? (Word 2003)

    Author
    Topic
    #437992

    Sometimes when I use Range.Delete to delete the whole range in a document, it fails (the return value is false). When I use Range.FormattedText to set the content of this Range, the new content does not replace the old content as it is supposed to do. It is inserted before the old content instead. Any one has a clue what makes the Range write-only?

    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #1043066

      Does it work better if you use ActiveDocument.Content instead of ActiveDocument.Range?

      If not, we’d need to have more information about the situation(s) and/or document(s) in which Delete fails.

      • #1043088

        I did more tests and got some detailed information.

        When the spelling and grammar check dialog is active, I can only perform Range.Delete in the active document. While I tried to do so in an inactive document, it failed. I tried it in a VBA macro, it pops out a message: ” This method or property is not available because the proofing dialog is active.”

        I cannot see any logic behind this rediculous limitation. I cannot activate a document just because I want to access it. Is there any way to avoid this problem?

        Thanks

        • #1043089

          The built-in dialogs and Word VBA use the same underlying engine; a lot of VBA code is unavailable when a built-in dialog is open. I don’t know a workaround (except, of course, closing the dialog before running the code).

          • #1043121

            Thanks Hans. That solves my puzzle.

            Are there any information that clears lists which VBA methods are not available when which dialogs are active?

            • #1043124

              I’ve never seen such a list. All modal dialogs (dialogs that won’t allow you to click in the document while they’re open) disable code execution if you haven’t opened them in your code. With the modeless dialogs such as Insert | Reference | Cross Reference the situation is not quite clear, and behavior appears to change between versions. I think it’s best to err on the safe side: assume that code won’t run correctly if the user has opened a dialog.

    Viewing 0 reply threads
    Reply To: Why Range.Delete failed? (Word 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: