Add Text Box at the Start of the selected page

I want to scroll to the specified page which I am able to do with the following command

if scrollType is "down" then
            page scroll of active window down scrollPages
        else
            page scroll of active window up scrollPages
        end if

       set textBox to make new text box at active document with properties {text orientation:horizontal, left position:100, top:100, width:100, height:100}
        set content of text range of text frame of textBox to "Test Box"

But able to add text Box only at the end what is the definite at value to use to create textBox at the specified page and not the end of the document

I think that it deposits the text box at the insertion point — at least, it does if you don’t specify a location more narrowly than ‘document’.

page scroll doesn’t affect the insertion point so I don’t think that there is any value in combining the two commands.

No insertion point is the selection in my case
And I have to select the first paragraph of a specific page is there a command for the same ?

I don’t want to specify the paragraph number to select a insertion point

There aren’t really any ‘page’ commands that I’m aware of. It’s not one of the elements of a document. You can work with words, paragraphs, sections, selection, etc…. You could also probably ‘find’ some text and work with that as well.

I suspect that you can’t use page because it can’t be relied upon. A user could change the font, for example, and that could push text to a different page and there isn’t really any way for the script to know that it happened.

app.ActiveWindow.Panes[1].Pages[5].Rectangles[1].Range.Select();

Was able to do this in windows, this apple script is confusing and doesn’t have support for most of the cases

I’d say you’re half right. It is confusing but to use your phrase, it does have support for most cases. I did just learn that there is a navigate command which allows you to move by page. There are various options to allow you to move around.

Now I’m not really sure what you want to do as I don’t know what your document looks like or where you’re trying to put a text box but here is a way to insert one into page 5 of the active document.

tell application "Microsoft Word"	
	
	set nto5 to navigate text object of selection to goto a page item position absolute count 5
	
	set textBox to make new text box at nto5 with properties {text orientation:horizontal, left position:100, top:100, width:100, height:100}
	set content of text range of text frame of textBox to "Test Box"
	
end tell

I should add that there is a run VB macro command. It has some restrictions but perhaps it might give you a more familiar approach to solving your problem.

1 Like

This is what I was expecting thanks for the solution. I just wanted to have the selection object at the specific page

1 Like