Returning items in a range

I am having an issue with returning the items within a range. I have included the code that I am using and it seems that arange is empty or something, because I can't get it to call any of the items that are in the range.


use scripting additions


set theXLSX to (choose file of type ("org.openxmlformats.spreadsheetml.sheet"))

set theDOCX to (choose file of type {"org.openxmlformats.wordprocessingml.document"})


tell application "Microsoft Excel"

activate

open file theXLSX


set numb to display dialog "What row is the project on?" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"


set numb2 to (text returned of numb) as integer


tell sheet3 of document 1

set arange to range ("A" & numb2 & ":K" & numb2)

end tell

end tell


tell application "Microsoft Excel" to if it is running then quit

tell application "Microsoft Word"

activate

open file theDOCX


set myfind to find object of text object of active document


set properties of myfind to {match case:false, match whole word:false, match wildcards:false}


execute find myfind find text ("<<project>>") replace with (item 1 of arange) replace replace all


close active document saving yes

end tell


tell application "Microsoft Word" to if it is running then quit

MacBook Pro 13″

Posted on Nov 9, 2023 9:23 AM

Reply
Question marked as Best reply

Posted on Nov 9, 2023 2:18 PM

this was the solve that I figured out. If anyone needs this for the future. This will have you choose a .docx file and then an .xlsx file from finder. Use the excel sheet to extract data from a specific sheet in the workbook. uses that information to fill out a form that was made in Word.


use scripting additions


set theXLSX to (choose file of type ("org.openxmlformats.spreadsheetml.sheet"))

set theDOCX to (choose file of type {"org.openxmlformats.wordprocessingml.document"})


tell application "Microsoft Excel"

activate

open file theXLSX


set numb to display dialog "What row is the project on?" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"

set numb2 to (text returned of numb) as integer

set range2 to range ("A" & numb2 & ":K" & numb2) of sheet "Small Jobs" of document 1

set range2Data to value of cells of range2


end tell


--tell application "Microsoft Excel" to if it is running then quit


tell application "Microsoft Word"

activate

open file theDOCX


set myfind to find object of text object of active document

set properties of myfind to {match case:false, match whole word:false, match wildcards:false}


execute find myfind find text ("<<project>>") replace with (item 1 of range2Data) replace replace all

execute find myfind find text ("<<field>>") replace with (item 2 of range2Data) replace replace all

execute find myfind find text ("<<contact>>") replace with (item 3 of range2Data) replace replace all

execute find myfind find text ("<<phone>>") replace with (item 4 of range2Data) replace replace all

execute find myfind find text ("<<street>>") replace with (item 5 of range2Data) replace replace all

execute find myfind find text ("<<citystatezip>>") replace with (item 6 of range2Data) replace replace all

execute find myfind find text ("<<visit>>") replace with (item 7 of range2Data) replace replace all

execute find myfind find text ("<<known>>") replace with (item 8 of range2Data) replace replace all

execute find myfind find text ("<<scheduled>>") replace with (item 11 of range2Data) replace replace all


print active document

close active document saving yes


end tell


tell application "Microsoft Word" to if it is running then quit

6 replies
Question marked as Best reply

Nov 9, 2023 2:18 PM in response to charles.christian14

this was the solve that I figured out. If anyone needs this for the future. This will have you choose a .docx file and then an .xlsx file from finder. Use the excel sheet to extract data from a specific sheet in the workbook. uses that information to fill out a form that was made in Word.


use scripting additions


set theXLSX to (choose file of type ("org.openxmlformats.spreadsheetml.sheet"))

set theDOCX to (choose file of type {"org.openxmlformats.wordprocessingml.document"})


tell application "Microsoft Excel"

activate

open file theXLSX


set numb to display dialog "What row is the project on?" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"

set numb2 to (text returned of numb) as integer

set range2 to range ("A" & numb2 & ":K" & numb2) of sheet "Small Jobs" of document 1

set range2Data to value of cells of range2


end tell


--tell application "Microsoft Excel" to if it is running then quit


tell application "Microsoft Word"

activate

open file theDOCX


set myfind to find object of text object of active document

set properties of myfind to {match case:false, match whole word:false, match wildcards:false}


execute find myfind find text ("<<project>>") replace with (item 1 of range2Data) replace replace all

execute find myfind find text ("<<field>>") replace with (item 2 of range2Data) replace replace all

execute find myfind find text ("<<contact>>") replace with (item 3 of range2Data) replace replace all

execute find myfind find text ("<<phone>>") replace with (item 4 of range2Data) replace replace all

execute find myfind find text ("<<street>>") replace with (item 5 of range2Data) replace replace all

execute find myfind find text ("<<citystatezip>>") replace with (item 6 of range2Data) replace replace all

execute find myfind find text ("<<visit>>") replace with (item 7 of range2Data) replace replace all

execute find myfind find text ("<<known>>") replace with (item 8 of range2Data) replace replace all

execute find myfind find text ("<<scheduled>>") replace with (item 11 of range2Data) replace replace all


print active document

close active document saving yes


end tell


tell application "Microsoft Word" to if it is running then quit

Nov 9, 2023 10:12 AM in response to charles.christian14

EDITED


arange is an object of Excel. Word doesn't have access to it, especially after end tell (app Excel).


I don't have Excel to test, but perhaps this would work. Create a list arangeData that carries the values from one to the other.



tell sheet3 of document 1

set arange to range ("A" & numb2 & ":K" & numb2)

set arangeData to {value of cells of arange}

end tell



execute find myfind find text ("<<project>>") replace with (item 1 of arangeData) replace replace all


Returning items in a range

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.