MS Word 2008: Copy content of text boxes and paste at end of document

I am trying to loop through all the text boxes in a MS Word document (Word 2008) and copy the contents of each text box and paste it at the end of the same word document. I’ve tried coding this several different ways but keep getting an error when I try to copy the contents. I’m sure I’m just doing something very obvious wrong??? My code is:

tell application “Microsoft Word”
activate
open myMsWordDoc2

	--Loop through text boxes and copy text to end of document
	tell active document
		set alltextboxes to (get text box)
		repeat with onetextbox from (count alltextboxes) to 1 by -1			
			set mytextcontent to contents of text box
			copy object mytextcontent
	
			--Paste at end of document
			collapse range text object of active document direction collapse end
			paste object text object of selection
		
		end repeat		
	end tell
		
	save the front document
	quit		
end tell

Thanks:)

OK I’m still hammering away at this problem. I’ve now fixed up my repeat statement and have decided to use the ‘get’ command rather than the ‘copy object’ command, but I still can’t seem to get the text content of the text box. This is the line (which I’ll use variables with once i get it working!):

get content of text range of text frame of text box 6 of active document

This returns “current application”??? rather than the text content of the text box.

Any ideas??:frowning:

I eventually got there in the end - was quite simple once i knew what I was doing!! :smiley:

My script is below in case its helpful to anyone else:

Tell Application “Microsoft Word”
–Loop through text boxes and copy text to end of document
tell active document
–alltextboxes variable stores a list of every text box in active document
set alltextboxes to (get every text box)
–each time the “repeat with” statement runs, Applescript sets onetextbox to the next text box in the list
repeat with onetextbox in alltextboxes
–Get the content of a text box
set MyTextContent to get content of text range of text frame of onetextbox
if MyTextContent is not missing value then
–Insert contents of textbox at end of document (preceded by carriage return)
insert text "
Text Box:" & MyTextContent at end of text object

				--else		
			end if
		end repeat
	end tell

end tell

Hello,

your code is very interesting. My question is, how to paste or insert the text into a text box?

Thanks!