AppleScript & MS Word Question

Discussion in 'Mac Programming' started by superscape, Jun 30, 2016.

  1. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #1
    Hi,

    I can't see anything obvious in the scripting dictionary, but does anyone know a way of finding the text of the last line on a single page of a Word document is (using AppleScript).

    Any clever ideas appreciated!

    Thanks
     
  2. kryten2, Jun 30, 2016
    Last edited: Jun 30, 2016

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Hi superscape,

    The sentences element looks like what you want. There's a similar thread : http://forums.macrumors.com/threads/applescript-ms-word-delete-last-sentence-paragraph.1767586/
    Forum member snorkelman seems to know a lot about scripting MS Word. You can also fall back to VBA.

    Example:

    Code:
    tell application "Microsoft Word"
        set myDoc to active document
        -- Working with the selection object
        select sentence -1 of myDoc
        get content of text object of selection
       
        -- Working with text range objects
        set myRange to create range myDoc start (start of content of sentence -1 of myDoc) end (end of content of sentence -1 of myDoc)
        get content of myRange
    end tell
     
  3. superscape thread starter macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #3
    Thanks, kryten2. That works great. I think I made a mistake explaining the problem though - I should have said that I wanted the last sentence on *each* page of a multi page document (my mistake).

    I'm not sure this is possible since Word doesn't seem to have a "page" object.

    I may have to have a word with snorkelman... unless you or anyone else has other ideas?
     
  4. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    When I was answering your question I was thinking good, he only wants to do something on a single page because like you noticed there isn't any page object in the dictionary. After a bit of searching I found an old post on macscripter. net and that didn't look good.

    Of course the link in the post is dead however I'll continue searching the net. There's got to be a way to do this.
     

Share This Page