¿Cómo obtener el rango de objeto de texto en un documento de Word que incluye un enlace?

1

No puedo obtener el rango de un documento si dicho documento contiene un enlace. Puedo obtener el rango de un objeto de texto en un documento de Word cuando no tiene un enlace, pero si el documento de Word tiene un enlace, el rango que obtengo es incorrecto para agregar texto después del enlace. Parece que necesito usar otro método para obtener el rango (¿de algo más que un objeto de texto?), Pero no sé qué es eso. Las horas de búsqueda en línea y de sumergirme en el diccionario solo me han llevado a lo siguiente.

(A pesar de la longitud del código a continuación, la pregunta que me interesa solo concierne a la última parte, cómo crear un rango que también capture el enlace, para poder agregar más texto correctamente).

Aquí está el código que me está dando problemas, si lo ejecuta con cualquier archivo utilizado como enlace en FilePath, agregará el enlace a un documento de Word pero no agregará el marcador final "Fin del correo electrónico":

set FilePath to (path to desktop) & "somefile.doc"
set FilePath to FilePath as string
set Filename to "ThisFile.txt"
tell application "Microsoft Word"
    activate
    tell active document --This is just a word document with or without text.
        --This creates a range to add the link
        set ContTemp to content of text object
        set StartRange to (count of ContTemp) - 1
        set endrange to StartRange
        set theRange to create range start StartRange end endrange
        --This adds the link (below the text, if there is any)
        tell theRange
            set CommentText to "Click here to open attachment " & Filename
            --set FilePath to "desktop/" & Filename & " "
            make new hyperlink object at end with properties {text to display:CommentText, hyperlink address:FilePath, text object:theRange}
        end tell
    end tell
    --This tries to add text "End of Email" after the link, but doesn't work.
    tell active document
        set EndOfEmail to return & return & " End of Email" & return as string
        set ContTemp to content of text object
        set StartRange to (count of ContTemp) - 1
        set endrange to StartRange
        set theRange to create range start StartRange end endrange
        set style of theRange to style normal
        set content of theRange to EndOfEmail
    end tell
end tell

El código de rango anterior funciona muy bien para agregar texto al documento, pero dado que el enlace tiene caracteres ocultos, supongo que este código no puede colocar el código en su lugar correcto. ¡Cualquier idea sería apreciada grandemente!

    
pregunta MBUST 10.05.2018 - 19:10

0 respuestas

Lea otras preguntas en las etiquetas